PROBLEMA [JAVA GUI] Lettore mp3 che non smette di suonare

Pubblicità
vedo che nel codice sono presenti dei Thread, forse è quello che mi mancava. Dopo provo, grazie mille :)
 
premetto che molto probabilmente non so neanche io quello che ho fatto :D
con l'uso del Thread il lettore non si impalla più. Posso cliccare sui pulsanti e chiudere la finestra.
per farlo funziona ho aggiungo alla Classe finestra una classe interna con il thread:
Codice:
public class PlayerThread extends Thread {

        public void run()

        {
            try {
                player.play();
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }
Posso anche caricare il file e poi premere play per far partire la musica. Il problema è: COME SI STOPPA?
perché leggendo ho capito che stop() non si usa più, però mica ho capito al suo posto cosa va inserito :(
interrupt mi pare servi a c... non mi ricordo più. Niente, insomma... non sto tanto bene come si può notare :D
 
a parte che è strano non abbia la funione pausa O__O
Comunque dopo 20000 tentativi ho fatto la cosa più semplice: player.close() e blocca il flusso :)
Ora devo capire 'sto fatto della pausa anche se JLayerPlayerPausable non lo trovo

EDIT:
secondo questa guida http://www.informit.com/guides/content.aspx?g=java&seqNum=290 pare che bisogni modificare il sorgente di JLayer per poter fare l'ovverride del metodo play() implementando resume e stop

Codice:
If you want to add pause and resume functionality to the Player, you will need to override the play() method, 
but this requires that you recompile the JLayer source code because some of the objects that are referenced in 
the play() method are private (instead of protected.) Specifically, I extended the Player class and replaced the 
following snippet from the play() method:

while (frames-- > 0 && ret)
{
 ret = decodeFrame();            
}

With:

while (frames-- > 0 && ret)
{
 if( this.playing )
 {
  ret = decodeFrame();            
 }
 else
 {
  try
  {
   Thread.sleep( 100 );
  }
  catch( Exception e )
  {
  }
 }
 }

And then added pause() and resume() methods that controlled the value of the playing boolean variable.
 
Ultima modifica:
sì, sì, infatti, ti ringrazio :)
anche c'ho provato tutt'oggi a capire come diavolo va implementato con la gui... boh, speriamo domani :)
ho postato anche l'altro metodo perché non si sa mai, magari qualcuno avrà il mio problema :)
 
Ultima modifica:
Pubblicità
Pubblicità
Indietro
Top