First time here? Check out the FAQ!
x

How to pause audio and then play it from where I paused?

0 votes
asked by (340 points) about NetBeans IDE
edited by

This is my play/pause code in Netbeans 7.3.1. I can't pause audio and play it from where I paused it. Is there any simple code?

My code:

if(jToggleButton1.getText().equals("Pause"))
                {
                    time=mediaPlayer.getCurrentTime();
                    mediaPlayer.stop();
                    jToggleButton1.setText("Play");
                    isplaying=false;
                }
                else
                {
                    mediaPlayer.setStartTime(time);
                    mediaPlayer.play();
                    jToggleButton1.setText("Pause");
                    isplaying=true;
                }

1 Answer

0 votes
answered by (80k points)
edited by

Try using threads and ActionListener. Something like this:

public void actionPerformed(ActionEvent evt) {
    SwingUtilities.invokeLater(new Runnable()  {
            public void run(); 
            mediaplayier.stop();
            } });
}

Here you can read more about ActionListener and threads.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register
...