Firing up Raspberry PI omxplayer using Java code
omxplayer -r -o hdmi myVideoFile.mp4
I have been working on a Spring Boot Restful application to be able to control the OMXPlayer on the Raspberry Pi . For now my Spring Boot application which runs on Raspberry Pi itself only provides a means to play a specified file and to stop the omxplayer .
Now whats interesting is that Spring Boot provides an easy means to quickly put up an executable jar file which can expose Restful endpoints . So next step is how to call the command above from Java on the Pi which is basically a unix system .
Play
Strangely as it sounds it took me a while to figure this out whilst navigating through stackoverflow , well its not that complicated.
All you need is a ProcessBuilder :
-----------------------------
ProcessBuilder pb = new ProcessBuilder("bash", "-c", "omxplayer -r -o hdmi myVideoFile.mp4");
Process process = pb.start();
StringBuffer sb = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(
p.getInputStream()));
String line = reader.readLine();
sb.append(line);
while (line != null) {
line = reader.readLine();
sb.append(line);
}
Note that in either case you can use the same codes above to execute the :

