10-29-2013 11:45 PM
I'm sorry if it is a dump question, but I still can not figure out how to get length (in seconds) of a media file (e.g. m4a file).
I have bunch of a media files & I want to iterate through them & get length of each one.
11-08-2013 01:40 PM
Here is a link to the documentation of the duration property of the MediaPlayer API: http://developer.blackberry.com/native/reference/c
11-08-2013 05:48 PM
Hi, I know that MediaPlayer API has duration property, however my question was about looping through a hundreds of audio files and get their duration to display in a list, so my concern in using duration property are:
- duration only available once durationChanged() signal fired (correct me if I'm wrong here), so it's not as easy as "open file, get duration, go next"
- looping through a hundreds of audio files and use MediaPlayer to parse each file just for duration information is a most efficient way (in term of processing time, memory usage, etc.)?
11-12-2013 01:28 PM - edited 11-12-2013 01:39 PM
- Based on the documentation, the duration is available once prepare() has been called and the file is ready to be played. It gets updated when the durationChanged() signal is fired.
"Provides the duration of a currently prepared track.
The duration of the current track is available once prepare() has been called, and the player has successfully acquired the resources to play the current track. The duration of the current track is no longer available when stop() has been called. In any other case, a duration of zero is returned."
- Here is one way to do it (i haven't tried it myself though): Define a single MediaPlayer object attached to your top control and in a loop (in C++ or in QML) loop on all media files in your list and change the sourceURL property. In the same loop, call the duration() method to retrieve the duration of the file.
11-12-2013 01:34 PM
Also, i suggest you try using the MetaData class, which seems to be an API that allows you to retrieve the metadata of media files including the duration property:
11-13-2013 02:25 AM
The key in your quoted doc is "The duration of the current track is available once prepare() has been called, and the player has successfully acquired the resources to play the current track."
So after prepare() is called, MediaPlayer will notified you about duration in durationChanged event once it's available. I've confirmed that by a simple sample to use MediaPlay in QML. Also, MetaData itself comes from MediaPlayer so it has the same rule.
That's what I've found so far, please correct me if anything's wrong.
02-11-2014 12:03 AM