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
New Developer
Posts: 46
Registered: ‎12-16-2010
My Device: Not Specified

Audio cuts out when I try to play using player.

Hello guys, in the app I am developing I download audio from a server and then play it back using the player class. Now the strange thing is this works 100% correctly in the emulator, but on the phone itself (8350i Nextel model) it downloads the same number of bytes but it cuts out the audio playing like about 95% though the audio and I can't detect that the audio ended through my player listener.

 

Here is my code for the downloader.

try
{
    FileConnection dest = (FileConnection)Connector.open("file:///store/home/user/documents/voting.mp3",Connector.READ_WRITE);

if (!dest.exists()) {
dest.create();
}
else
{
 dest.delete();
 dest.create();   
}
OutputStream outStream = dest.openOutputStream();
HttpConnection connection = null;
InputStream inputStream = null;

connection = (HttpConnection) Connector.open("http://server.mp3", Connector.READ_WRITE, true); //Can't give out real server link.
inputStream = connection.openInputStream();


byte[] Buffer = new byte[1024];
int temp = 0;
int amount = 0;
int length = (int)connection.getLength();
while ((amount != length)) {
temp = inputStream.read(Buffer);
amount = amount + temp; 
outStream.write(Buffer);

System.out.println(amount);
}


connection.close();
outStream.close();


}
catch (Exception e){

}

 

 

and for the player:

 

String file = "file:///store/home/user/documents/voting.mp3" ;
myPlayer = Manager.createPlayer(file);
myPlayer.realize();
myPlayer.prefetch();
myPlayer.setLoopCount(1);
vc = (VolumeControl)
myPlayer.getControl("VolumeControl");
vc.setLevel(25);

VotingListener v = new VotingListener();//Player Listener myPlayer.addPlayerListener(v);
myPlayer.start();

} catch (Exception e) {

System.out.println(e.toString());
}

 

 

I am kinda clueless on why it would work exactly correctly through the emulator but not on the actual phone itself. Anyone got any ideas?

 

Thanks