I'm trying to create a program allowing me to execute a command through a terminal (which is OmxPlayer for raspberry pi if you want to know) with arguments, but i'd want to be able to interact with it once I have launched the command.
For example i'd want to do : omxplayer -win x1 y1 x2 y2 and then be able to press "p" to pause the video/audio media
I already have something that can launch the omxplayer with arguments (actually it's "ls" but it should work exactly the same way) but I don't understand how to interact with the terminal once i've launched the command through the processBuilder.
Here's what i've got at the moment :
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class Main1 {
public static void main(String a[]){
InputStream is = null;
ByteArrayOutputStream baos = null;
List<String> commands = new ArrayList<String>();
commands.add("ls");
commands.add("-l");
commands.add("/");
ProcessBuilder pb = new ProcessBuilder(commands);
try {
Process prs = pb.start();
is = prs.getInputStream();
byte[] b = new byte[1024];
int size = 0;
baos = new ByteArrayOutputStream();
while((size = is.read(b)) != -1){
baos.write(b, 0, size);
}
System.out.println(new String(baos.toByteArray()));
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try {
if(is != null) is.close();
if(baos != null) baos.close();
} catch (Exception ex){}
}
}
}