Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 37
Registered: ‎10-10-2008
My Device: Not Specified

Anyone successful with getDuration() on mp3 Player??

Has anyone been sucessful with the getDuration() function on an mp3 file? It works for .wav, m4a, midi, but not mp3 for some strange reason.

 

Get player.getduration() has been returning -1 or 0 for me.

 

I'm trying to create a progress slider in an mp3 player application.

BlackBerry Development Advisor
Posts: 15,752
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Anyone successful with getDuration() on mp3 Player??

I tried this using the BlackBerry Bold simulator included with the version 4.6.0 BlackBerry JDE and the duration was returned.  What BlackBerry model and handheld software version are you testing on?  You can find this under Options, About on the BlackBerry handheld.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 37
Registered: ‎10-10-2008
My Device: Not Specified

Re: Anyone successful with getDuration() on mp3 Player??

I am playing the Alarm Early Riser that comes default on the blackberry simulator.

"file:///store/samples/ringtones/Alarm_EarlyRiser.mp3" if its the same path on your device.

 

Running on the 8820 Simulator. v4.2.2.124

 

I'm only having problems with the MP3. Can you show me code you are using to get duration? This is exactly what I'm doing.

from: javax.microedition.media.Player;

 

Player p =  Manager.createPlayer(in, "audio/mpeg");

I'm calling player.getMediaTime()  and player.getDuration()

 

getMediaTime() gives me timeupdate progress as the player is playing,

getDuration() keeps reporting -1, on .mp3 files.

 

I didn't have a problem with .wav files, .m4a

 

I've tried on various random .mp3 files, and got the same result.

BlackBerry Development Advisor
Posts: 15,752
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Anyone successful with getDuration() on mp3 Player??

I used it after the player had already started.

 

Note that you are not able to reference the built in media files on a real BlackBerry handheld.  They are copy protected and not accessible from third party applications.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 37
Registered: ‎10-10-2008
My Device: Not Specified

Re: Anyone successful with getDuration() on mp3 Player??

I'm also calling getDuration() from within a PlayerListener after the Player started. I'm even calling it ever time the player listener fires a com.rim.timeUpdate event in the listener.

 

I've tried it on other .mp3 files I added myself.

Developer
Posts: 21
Registered: ‎11-09-2009
My Device: Not Specified

Re: Anyone successful with getDuration() on mp3 Player??

Hi Guys,

 

I'm experiencing the same problem. Anyone got a solution to this already? GetDuration() keeps returning -1 on .mp3 files, getMediaTime() works normal. I am on 4.6.0 Simulator. Don't know if it makes a difference but I am streaming a remote file (nevertheless it works with a rtsp stream) with Manager.createPlayer(stream,type). Have not tried local files yet.

 

Cheers,

Rob

Highlighted
Developer
Posts: 148
Registered: ‎11-16-2009
My Device: Not Specified

Re: Anyone successful with getDuration() on mp3 Player??

[ Edited ]

Can you provide your sample code, how you tried it ?

I tried with custom DataSource and then i got something back, but when i convert it to minutes and seconds it return much more then the expected. The inbuild media player shows 4 min and 05 sec and i got back 27 min and 43 seconds....

Any idea what i made wrong ? I think i did something worng in the custom DataSource, however i can play the mp3 programmatically.