I am developing a J2ME application for Nokia 6630.
In which I'm trying to play audio (.mp3 & .amr formats).
I use " player.stop(); " to pause audio.
But when I try to resume audio, Player strarts audio from beginning.


import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.media.PlayerListener.*;
import java.lang.String.*;
import javax.microedition.rms.*;

final class PlayerCanvas implements Runnable {
private Player player = null;
private Thread dThread = null;
private InputStream s2 = null;
PlayerCanvas(InputStream s1){
super();
s2=s1;
}
private void createPlayer() {
try {
player = Manager.createPlayer(s2, "audio/mpeg");

}
catch (Exception e) {
}
}
public final void playSound() {
if (dThread == null) {
dThread = new Thread(this);
dThread.start();
} else if (player != null) {
try {
player.start();
} catch (Exception ex){

}
}
}


public final void stopSound() {

try {
dThread = null;

if (player != null) {
player.stop();
player.close();
player = null;
s2.close();
s2=null;
}
} catch (Exception ex) {
System.err.println("Problem closing player");
}
}


final void pauseSound() {//to pause audio
try {
if (player != null)
player.stop();

} catch (Exception ex){
System.err.println("Problem stopping player");
}
}


public final void run()
{
if (player == null)
{
try {

createPlayer();
player.realize();
player.prefetch();
player.start();
}
catch(Exception me1)
{
}
}
}

}

1 ) i use createPlayer() method to create player
2 ) i call playSound() method audio play . then i use
pauseSound() to stop audio,audio stop but when i call once again playSound() method audio start from beginning.

The stop method will stop the sound completely, not at a specific. You need something that will actually pause it, instead of stoping the audio..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.