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

Sergei

Utente Attivo
115
1
vedo che nel codice sono presenti dei Thread, forse è quello che mi mancava. Dopo provo, grazie mille :)
 

Sergei

Utente Attivo
115
1
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
 

Sergei

Utente Attivo
115
1
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:

cawletto

Utente Attivo
475
25
CPU
i5 750
HDD
1 TB
RAM
6 GB
GPU
GXT 460 SE 1GB overclocked
Monitor
Samsung LCD 1280x1024
PSU
Cooler Master Silent Pro M 600 W
Case
HP
OS
Windows 7-64 bit
Nella guida che ti ho linkato c'è proprio scritto come devi fare per poter usare pause e resume. :)
 

Sergei

Utente Attivo
115
1
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:

Entra

oppure Accedi utilizzando
Discord Ufficiale Entra ora!