0

I'm using JLayer to play mp3 files in my game, but It's impossible for me to stop the song. That's my code:

public void play(final String sonido) {

    reproduciendo.put(sonido, 1);
    Thread thread = new Thread() {
        public void run() {
            while(reproduciendo.get(sonido)!=null) {
            try {
            Player player = new Player(getSonido(sonido));
            player.play();
            if(player.isComplete()) reproduciendo.remove(sonido);
            } catch(Exception e) {e.printStackTrace();};
        }}
    };

    thread.start();

}


public void stop (String sonido ) {
    reproduciendo.remove(sonido);
}

When I remove the song of the hashmap "reproduciendo" with the stop method it should stop, but nothing is done, I've read this way here, but it doesn't work for me. Do you know another way to do it?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
jramirez
  • 486
  • 9
  • 24
  • I feel you made a poor choice in your [previous question](http://stackoverflow.com/q/16087152/418556) in choosing JLayer while ignoring my advice. I've added the JLayer tag to this question and notice that it has 1/5 the followers that Java Sound has. It is quite easy to stop a sound being played by Java Sound. – Andrew Thompson Apr 20 '13 at 03:20

2 Answers2

0

I don't know what library you are using, but maybe you could find a "stop" method in your player class.

P. Lalonde
  • 694
  • 1
  • 7
  • 17
0

see my answer to other similar question, just play one audio frame and check a flag if it should pause or stop playing

https://stackoverflow.com/a/16738486/2094045

Community
  • 1
  • 1
Anthony Ho
  • 121
  • 6