Audio file problem
The netbeans compiles okay but mobile emulator can not play sound file (.amr). as I dont have download accessories, I can't test the code on my phone. Any idea?
....
elseif (c == playCommand)
{
start();
this.removeCommand(playCommand);
this.addCommand(pauseCommand);
}
elseif (c == pauseCommand)
{
pause();
this.removeCommand(pauseCommand);
this.addCommand(playCommand);
}
}
publicvoid start()
{
Thread t =new Thread(this);
t.start();
}
// to prevent blocking, all communication should be in a thread and not in commandAction
publicvoid run()
{
play();
}
void play()
{
try
{
if(p==null || !(p.getMediaTime()<p.getDuration()))
{
String fName = this.currentHS.getSoundFilename();
if(fName==null)
{
this.removeCommand(pauseCommand);
this.addCommand(playCommand);
return;
}
InputStream is = this.getClass().getResourceAsStream(fName);
p = Manager.createPlayer(is,"audio/amr");
p.addPlayerListener(this);
p.prefetch();
p.realize();
p.start();
}
else
{
p.start();
}
}
catch(IOException e)
{
System.out.println("Error in io : " + e.toString());
}
catch(MediaException e)
{
System.out.println("Error in media : " + e.toString());
}
}
void pause()
{
try
{
p.stop();
}
catch(MediaException e)
{
System.out.println("Error in media : " + e.toString());
}
}
publicvoid playerUpdate(Player player, String str, Object obj)
{
if(str.toLowerCase().equals("endofmedia"))
{
this.removeCommand(pauseCommand);
this.addCommand(playCommand);
}
}
.......
>

