Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8022825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:23:00+00:00 2026-06-04T22:23:00+00:00

I am making a mp3Player in java with the library from javazoom. I have

  • 0

I am making a mp3Player in java with the library from javazoom. I have manged to start and stop the mp3 but i cant resume it. Does anyone know how to do this?

Here is the MP3Player class:

public class MP3Player extends JFrame{

public MP3Player(){
    JPanel jpBottom = new JPanel();
    JButton btnPlay = new JButton("Play");
    JButton btnPause = new JButton("Pause");

    jpBottom.add(btnPause);
    jpBottom.add(btnPlay);

    Container cp = this.getContentPane();
    BorderLayout bl = new BorderLayout();
    cp.setLayout(bl);
    cp.add(jpBottom, BorderLayout.SOUTH);

    btnPlay.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if(t.isInterrupted()){
                        t.resume();
                    } else{
                        t.start();
                    }
                }
            }
    );

    btnPause.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent e){
                   t.interrupt();
                }
            }
    );

    this.setVisible(true);
    this.setSize(250, 100);
    this.setTitle("MP3 Player");
    this.setLocation(100, 100);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

Thread t = new Thread(new PlayerThread("file:///C://a.mp3"));

public static void main(String[] args) {
    MP3Player n = new MP3Player();
}
}

The PlayerThread class:

public class PlayerThread implements Runnable{

    String path;
    PlayerThread(String path){
        this.path = path;
    }

    public void run(){
        try{
            URL url = new URL(path);
            InputStream in = url.openStream();
            AdvancedPlayer pl = new AdvancedPlayer(in);
            pl.play();
        }
        catch(Exception e){
            System.out.println("Error: "+e);
        }
    }

    public void pause(){
        Thread.interrupted();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:23:03+00:00Added an answer on June 4, 2026 at 10:23 pm

    It looks like you’re making a lot of assumptions that things will “just work”, without reading the APIs for the libraries you’re using.

    Firstly, interrupting a thread simply sets a flag on that thread. By convention, blocking calls will usually inspect this flag periodically and terminate early by throwing an InterruptedException if that is the case. But that’s not an automatic guarantee, and a caller cannot forcibly interrupt another thread. You need to ensure that interruption will do what you expect.

    Your pause() method is doubly wrong in that you’re not even setting the interrupted flag; Thread.interrupted() checks whether the current thread is interrupted (returning a boolean).

    Let’s go back to basics – you’re playing sound by calling AdvancedPlayer.play(). How do you get an AdvancedPlayer to pause? Looking through its documentation, it seems like it doesn’t support pausing in any obvious way. (There’s a stop() method but I don’t believe it would resume from the same place). And since the method doesn’t throw InterruptedException, it’s almost guaranteed that it doesn’t respond to interrupts.

    However, there is a BasicPlayer class that does have a pause. Is there any reason why you couldn’t use that instead, something like (ignoring exceptions):

    public class PlayerThread implements Runnable{
        final BasicPlayer player;
    
        PlayerThread(String path){
            player = new BasicPlayer(new URL(path).openStream());
        }
    
        public void run(){
            player.player();
        }
    
        public void pause() {
            player.pause();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple MP3Player in Java. I have managed to play a .mp3
I am making my own crude MP3 player, and I now have a JList
im making an application where i have to load my database from html file
Im making a game in Java with a few other people but we are
Making UI programmatically is very powerful. But is there a way I would have
Just making a really simple Tcl/Tk program to learn, but I'm having a little
I am currently making an MP3 player in WPF, and I want to make
Making a mobile friendly site, I have a single field and a submit button.
making a new jsp and got a mock-up from some analyst. Notice the sections
I'm making a jQuery MP3 player. The song structure is first generated (including the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.