Skip to content
Browse files

stop all mplayer playbacks and at the end stop all audio player and kill

all Threads
  • Loading branch information...
1 parent 8e50e37 commit c1b202cfd22f67af984b0c4baaba85aba48eb254 @Eule committed Dec 22, 2011
Showing with 41 additions and 12 deletions.
  1. +2 −1 etc/TODO
  2. +6 −0 src/gui/Gui_StreamRipStar.java
  3. +24 −10 src/gui/Gui_TablePanel.java
  4. +9 −1 src/thread/AudioPlayer_Mplayer.java
View
3 etc/TODO
@@ -1,3 +1,4 @@
- systray -> more functions
- language panel in JList -> may with flags as indicators
-- recognize when no mplayer instance is running
+- recognize when no mplayer instance is running
+- max log file -> delete, truncate
View
6 src/gui/Gui_StreamRipStar.java
@@ -864,6 +864,9 @@ public void closeAll() {
//save the settings for the mainwindow
saveProp();
+ //stop all playing streams
+ table.stopInternalAudioPlayer();
+
//stop all recording streams
controlStreams.stopAllStreams();
@@ -880,6 +883,9 @@ public void closeAll() {
//save the settings for the mainwindow
saveProp();
+ //stop all playing streams
+ table.stopInternalAudioPlayer();
+
//stop all recording streams
controlStreams.stopAllStreams();
View
34 src/gui/Gui_TablePanel.java
@@ -21,9 +21,12 @@
import java.net.URI;
import java.net.URL;
import java.net.URLDecoder;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+import java.util.Set;
import java.util.Vector;
import javax.swing.ImageIcon;
@@ -77,7 +80,7 @@
private ImageIcon recordIcon = new ImageIcon((URL)getClass().getResource("/Icons/record_middle.png"));
private JPopupMenu popup;
- private AudioPlayer_Mplayer player;
+ private Vector<AudioPlayer_Mplayer> allPlayers = new Vector<AudioPlayer_Mplayer>(0,1);
public Gui_TablePanel(Control_Stream controlStreams,Gui_StreamRipStar mainGui) {
this.controlStreams = controlStreams;
@@ -462,8 +465,9 @@ public synchronized void startMusicPlayerWithSelectedStream() {
if(mainGui.useInternalAudioPlayer())
{
stopInternalAudioPlayer();
- player = new AudioPlayer_Mplayer(stream[0], mainGui);
+ AudioPlayer_Mplayer player = new AudioPlayer_Mplayer(stream[0], mainGui);
player.start();
+ allPlayers.add(player);
} else {
controlStreams.startMp3Player("http://127.0.0.1:"+stream[0].relayServerPortTF);
}
@@ -473,8 +477,9 @@ public synchronized void startMusicPlayerWithSelectedStream() {
if(mainGui.useInternalAudioPlayer())
{
stopInternalAudioPlayer();
- player = new AudioPlayer_Mplayer(stream[0], mainGui);
+ AudioPlayer_Mplayer player = new AudioPlayer_Mplayer(stream[0], mainGui);
player.start();
+ allPlayers.add(player);
} else {
controlStreams.startMp3Player(stream[0].address);
}
@@ -498,9 +503,9 @@ public synchronized void startMusicPlayerWithSelectedStream() {
*/
public synchronized void setAudioVolume(int percentage)
{
- if(player != null && percentage >= 0 && percentage <= 100)
+ if(allPlayers.lastElement() != null && percentage >= 0 && percentage <= 100)
{
- player.setAudioVolum(percentage);
+ allPlayers.lastElement().setAudioVolum(percentage);
SRSOutput.getInstance().logD("Lautstärke ist nun: "+percentage);
}
}
@@ -523,17 +528,19 @@ public synchronized void startMusicPlayerWithUrl(String url, String name) {
if(stream.getStatus() && stream.connectToRelayCB) {
if(mainGui.useInternalAudioPlayer()) {
stopInternalAudioPlayer();
- player = new AudioPlayer_Mplayer(stream, mainGui);
+ AudioPlayer_Mplayer player = new AudioPlayer_Mplayer(stream, mainGui);
player.start();
+ allPlayers.add(player);
} else {
controlStreams.startMp3Player("http://127.0.0.1:"+stream.relayServerPortTF);
}
} else if(stream.address != null && !stream.address.equals("")) {
if(mainGui.useInternalAudioPlayer()) {
stopInternalAudioPlayer();
- player = new AudioPlayer_Mplayer(stream, mainGui);
+ AudioPlayer_Mplayer player = new AudioPlayer_Mplayer(stream, mainGui);
player.start();
+ allPlayers.add(player);
} else {
controlStreams.startMp3Player(stream.address);
}
@@ -548,9 +555,16 @@ public synchronized void startMusicPlayerWithUrl(String url, String name) {
* Stops the Thread with the internal audioplayer, if there is one
*/
public synchronized void stopInternalAudioPlayer() {
- if(player != null) {
- player.stopPlaying();
- }
+ for (final AudioPlayer_Mplayer player : allPlayers)
+ {
+ if(player != null)
+ {
+ player.stopPlaying();
+ player.killThread();
+ }
+ }
+
+ allPlayers.trimToSize();
}
public Gui_StreamRipStar getMainGui() {
View
10 src/thread/AudioPlayer_Mplayer.java
@@ -19,7 +19,7 @@
* @author Johannes Putzke
*
*/
-public class AudioPlayer_Mplayer extends Thread{
+public class AudioPlayer_Mplayer extends Thread {
private ResourceBundle trans = ResourceBundle.getBundle("translations.StreamRipStar");
private Stream stream;
@@ -148,4 +148,12 @@ public void setAudioVolum(int volumePercent)
}
}
+
+ /**
+ * Kills this thread
+ */
+ public void killThread()
+ {
+ mplayerProcess.destroy();
+ }
}

0 comments on commit c1b202c

Please sign in to comment.
Something went wrong with that request. Please try again.