I would like to get the length of an mp3 file (it can be local or external), so wp_read_audio_metadata($url) is my solution, but when I use it in my function.php it return “undefined function” ! Why ? should have to activate something ?
The wp_read_audio_metadata() function reads metadata from a specific file, but it is a heavy function so it, along with most of the other media uploader functions, are not included by default in a normal WP load process.
The way WordPress works is that when you upload a file, these functions read all sorts of metadata from the files, and then save that metadata in the database. So if your file is uploaded through the normal media system, then an “attachment” post is created, and the metadata is already saved, attached to that post. You can use the normal post meta functions to retrieve and display it instead of reparsing the file every time.
If you do need to parse a file not in the media system, then you need to manually include the WP administration functions (which includes the media functions, and others), by including the /wp-admin/includes/admin.php file.
Note that wp_read_audio_metadata() does not take a URL, it takes a file path. It can only parse local files, not external URLs.
Thanks a lot for your help and your precise answer !
I finally find a way to get length of an external file. The trick is to download a very small part of the file, calculating the length of that, then extrapolate to the entire file. Here someone write a function to do that : http://www.getid3.org/phpBB3/viewtopic.php?f=7&t=1208
To use this function in wordress I just had to change
require_once( ABSPATH . 'wp-includes/ID3/getid3.php' )
to include the getID3 library.
But sure, this function is really slow, so I run it only one time when I save or update the post
add_action( 'save_post', 'save_sound_length' );
- The topic ‘Call to undefined function wp_read_audio_metadata()’ is closed to new replies.