Permalink
Browse files

use the processbuilder instead of the normal process

  • Loading branch information...
1 parent 6ec8bce commit 016e03150c688b2f8db1302defaaaba9dfc29ee5 @Eule committed Jul 30, 2011
Showing with 17 additions and 8 deletions.
  1. +17 −8 src/thread/AudioPlayer_Mplayer.java
@@ -6,6 +6,8 @@
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ResourceBundle;
+import java.util.Vector;
+
import misc.Stream;
import control.SRSOutput;
import gui.Gui_StreamRipStar;
@@ -25,8 +27,8 @@
private SRSOutput lg = SRSOutput.getInstance();
private String mplayerPath = "/usr/bin/mplayer";
- private String mplayerOptions = "";
private int MPLAYER_CACHE = 128;
+ private Vector<String> options = new Vector<String>(0,1);
private BufferedReader inStream = null;
private BufferedWriter outStream = null;
@@ -56,22 +58,29 @@ public void run()
{
//do we need the local or the stream from the net?
if(stream.getStatus() && stream.connectToRelayCB) {
- mplayerOptions += " http://127.0.0.1:"+stream.relayServerPortTF;
+ options.add("http://127.0.0.1:"+stream.relayServerPortTF);
} else {
- mplayerOptions += stream.address;
+ options.add(stream.address);
}
//collect the options
- mplayerOptions += " -slave -quiet -cache "+MPLAYER_CACHE;
+ options.add(0,mplayerPath);
+ options.add("-slave");
+ options.add("-quiet");
+ options.add("-cache");
+ options.add(String.valueOf(MPLAYER_CACHE));
+
//say, we are loading the stream
if (mainGui != null)
{
mainGui.showMessageInTray(trans.getString("audioplayer.loadingStream"));
}
//start the process itself
- lg.log("AudioPlayer: Start music with mplayer command: "+mplayerPath+" "+mplayerOptions);
- mplayerProcess = Runtime.getRuntime().exec(mplayerPath+" "+mplayerOptions);
+ lg.log("AudioPlayer: Start music with mplayer command: "+mplayerPath+" "+options.toString());
+// mplayerProcess = Runtime.getRuntime().exec(mplayerPath+" "+mplayerOptions);
+//
+ mplayerProcess = new ProcessBuilder(options).start();
//create the streams we need to interact
inStream = new BufferedReader(new InputStreamReader(mplayerProcess.getInputStream()));
@@ -90,9 +99,9 @@ public void run()
}
} catch (IOException e) {
- lg.logE("Error while executing mplayer: "+mplayerPath+" "+mplayerOptions+e.getMessage());
+ lg.logE("Error while executing mplayer: "+options.toString()+e.getMessage());
} catch (Exception e) {
- lg.logE("Error while executing mplayer: "+mplayerPath+" "+mplayerOptions+e.getMessage());
+ lg.logE("Error while executing mplayer: "+options.toString()+e.getMessage());
}
}

0 comments on commit 016e031

Please sign in to comment.