wp_read_audio_metadata
Retrieve metadata from a audio file's ID3 tags.
Description
(array|bool) wp_read_audio_metadata( (string) $file );
Returns (array|bool)
Returns array of metadata, if found.
Parameters (1)
- 0. $file (string)
- Path to file.
Usage
if ( !function_exists( 'wp_read_audio_metadata' ) ) { require_once ABSPATH . '/wp-admin/includes/media.php'; } // Path to file. $file = ''; // NOTICE! Understand what this does before running. $result = wp_read_audio_metadata($file);
Defined (1)
The function is defined in the following location(s).
- /wp-admin/includes/media.php
- function wp_read_audio_metadata( $file ) {
- if ( ! file_exists( $file ) ) {
- return false;
- }
- $metadata = array();
- if ( ! defined( 'GETID3_TEMP_DIR' ) ) {
- define( 'GETID3_TEMP_DIR', get_temp_dir() );
- }
- if ( ! class_exists( 'getID3', false ) ) {
- }
- $id3 = new getID3();
- $data = $id3->analyze( $file );
- if ( ! empty( $data['audio'] ) ) {
- unset( $data['audio']['streams'] );
- $metadata = $data['audio'];
- }
- if ( ! empty( $data['fileformat'] ) )
- $metadata['fileformat'] = $data['fileformat'];
- if ( ! empty( $data['filesize'] ) )
- $metadata['filesize'] = (int) $data['filesize'];
- if ( ! empty( $data['mime_type'] ) )
- $metadata['mime_type'] = $data['mime_type'];
- if ( ! empty( $data['playtime_seconds'] ) )
- $metadata['length'] = (int) round( $data['playtime_seconds'] );
- if ( ! empty( $data['playtime_string'] ) )
- $metadata['length_formatted'] = $data['playtime_string'];
- wp_add_id3_tag_data( $metadata, $data );
- return $metadata;
- }