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
Super Contributor
Posts: 308
Registered: ‎05-31-2011
My Device: Blackberry-SDK-9800
My Carrier: SimPakage 6.0.0.337_9800 asia.exe

problem with _player.getDuration...

hello friends,

before playing the wav file i want to get its duration so that i would implement it in progress bar... but everytime its showing -1 as output......... 

i will write the code below..

public void play() {
try
{
if(_output==null){
Dialog.alert("No audio bytes");
}else{
Dialog.alert("follow btes");
_data = _output.toByteArray();
ByteArrayInputStream bi = new ByteArrayInputStream(_data);


_player = javax.microedition.media.Manager.createPlayer("file:///SDCard/BlackBerry/voicenotes/Testplay.wav");

if(_player.getState() != Player.STARTED){
_player.realize();
_player.prefetch();
_player.start();
long second = (int) _player.getDuration() / 1000000;
Dialog.alert(Long.toString(second));// conversion to seconds
}
_player.realize();
VolumeControl volume = (VolumeControl)_player.getControl("VolumeControl");
volume.setLevel(80);
_player.prefetch();
_player.start();


}
}
catch(MediaException me)
{
Dialog.alert(me.toString());
}
catch(IOException ioe)
{
Dialog.alert(ioe.toString());
}

}

 

 here i am getting seconds=-1... 

Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: problem with _player.getDuration...

Hello yogesh,

 

Can you please confirm your device OS version and model, as well as the OS version you are buliding for in your development environment? I'll give this a run here to confirm.

 

Erik Oros

BlackBerry Development Advisor


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Super Contributor
Posts: 308
Registered: ‎05-31-2011
My Device: Blackberry-SDK-9800
My Carrier: SimPakage 6.0.0.337_9800 asia.exe

Re: problem with _player.getDuration...

i am developing in simulator, 9800.....i.e OS version is 6.

Super Contributor
Posts: 308
Registered: ‎05-31-2011
My Device: Blackberry-SDK-9800
My Carrier: SimPakage 6.0.0.337_9800 asia.exe

Re: problem with _player.getDuration...

and how it depends on OS as its API for blackberry OS 6 version, it must run , i dont know what is the problem..

Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: problem with _player.getDuration...

[ Edited ]

Hello yogesh,

 

I just tested with your code running on a 9800 simulator with OS 6.0.0.246. In my case, the correct seconds value was returned.

 

Can you please elaborate how you are generating/where you are getting this file from:

file:///SDCard/BlackBerry/voicenotes/Testplay.wav

 

In my case, when I recorded a sample audio file to test via the Voice Notes Recorder application, the file that was generated was an AMR, not WAV. I am wondering whether it might actually be your audio file's format that is preventing the API from being able to calculate the duration.

 

Erik Oros

BlackBerry Development Advisor


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Super Contributor
Posts: 308
Registered: ‎05-31-2011
My Device: Blackberry-SDK-9800
My Carrier: SimPakage 6.0.0.337_9800 asia.exe

Re: problem with _player.getDuration...

ya, u r right... i am getting PCM file, and then i am converting this pcm file to wav file by adding headers to raw bytes of PCM.... but what u told is the genrated wav fie has the problem,,,,,, i will check with some standerd wav file and check..... plz be in touch...

Retired
Posts: 1,561
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: problem with _player.getDuration...

Sure thing, keep us posted here.

 

Just as a quick check to ensure the API itself is working properly for you in the first place, I would recommend a test using the recording application to generate an AMR file and confirm with your code that the duration is returned properly in that scenario.

 

Erik Oros

BlackBerry Development Advisor


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Highlighted
New Contributor
Posts: 4
Registered: ‎10-12-2011
My Device: bold
My Carrier: airtel

Re: problem with _player.getDuration...

Any updates on this issue? I'm facing same problem

      jde version- 4.6

      simulator 9000 bold

 

I'm trying to use mp3 with inputstream. this works fine for 6.0 and simulator 9800 but get duration 0 for 4.6 jde.

 

Any help will be appreciated.

Thanks!