diff --git a/src/main/java/musicplayer/player/GStreamerPlayer.java b/src/main/java/musicplayer/player/GStreamerPlayer.java index 82988dc..22175fa 100644 --- a/src/main/java/musicplayer/player/GStreamerPlayer.java +++ b/src/main/java/musicplayer/player/GStreamerPlayer.java @@ -22,7 +22,7 @@ public class GStreamerPlayer implements IPlayer{ private final PlayBin2 playBin; - private InternalThread internalThread; + private final InternalThread internalThread = new InternalThread(); private Thread thread; private Song currentSong; private final PlayerCallbackInterface callbackInterface; @@ -62,9 +62,9 @@ public class GStreamerPlayer implements IPlayer{ playSong(currentSong); else playSong(playlist.getNext(currentSong)); - } catch (InterruptedException | StartPlayingException e) { + } catch (StartPlayingException e) { e.printStackTrace(); - } + } catch (InterruptedException ignored){} }); callbackThing.start(); }); @@ -108,8 +108,10 @@ public class GStreamerPlayer implements IPlayer{ * @throws StartPlayingException */ private void playSong(Song inputSong) throws StartPlayingException { - if (playBin.getState() == State.PLAYING) + if (playBin.getState() == State.PLAYING) { + internalThread.stop(); stop(); + } if(playBin.getState() == State.PAUSED && inputSong == currentSong) { resume(); return; @@ -125,11 +127,10 @@ public class GStreamerPlayer implements IPlayer{ return; } playBin.setURI(songFile.toURI()); - internalThread = new InternalThread(); - thread = new Thread(internalThread, "GSTThread"); setVolume(currentVolume); playBin.play(); if(playBin.getState() == State.PLAYING) { + thread = new Thread(internalThread, "GSTThread"); thread.start(); while (true) { if (playBin.queryDuration().getSeconds() > 0 || playBin.queryDuration().getNanoSeconds() > 0) break;