Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Saturday, January 04, 2014

Firing up Raspberry PI omxplayer using Java code

The Pi has an excellent HDMI media player called omxplayer but it fails short in terms of interface to interact with , for starters by default you can interact with it only via command line for example the following command will play an mp4 file:

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);
}
-------------------------------------------

The ProcessBuilder will execute a Java process which in turn execute your omxplayer play command on the unix system , the output of this operation is returned back to the sb StringBuffer . 


Stop

Currently I couldn't find an elegant way to stop the playback though so what am doing is that am literally killing the process using the kill command e.g :

kill -9 3144

where 3144 is some PID (Process ID) which you need to capture to kill the process (executed through the process builder) , note that each time you fire off the omxplayer it will have a different ID.

Note that I use the following  command to get the PID 

ps -ef |egrep \"/usr/bin/omxplayer.bin


This will give you something as shown in the screenshot below :





Note that in either case you can use the same codes above to execute the :

1. codes that will return you the output from which you can then extract the PID 
2. execute the kill command to stop the process 

So that's as simple as it is for now.

Saturday, February 17, 2007

Maven 2.0.5 is out

Yes the new version of my favorite all time build tool is out with version 2.0.5 , I have been using Maven since its initial version and development life was never the same afterwards.

The guys at Apache promise a seamless upgrade from version 2.0.4 which has already been a while on the market.

Needless to say that I have already downloaded this new version and have it installed on my home pc ..my office workstation will have to wait until I have verified that all the builds indeed work without any hitch.



The version 2.0.6 shouldn't take too long to surface either.

Wednesday, January 24, 2007

Maven2 SSH site deploy Tip

Am gonna walk you into how to achieve deployment of maven site from a windows XP machine to a Redhat box, assuming you already have installed maven2 and the know-how to execute commands.

These are the stuffs which you need to perform:

1. Configure your POM.xml by adding the distribution management tag:

< distributionmanagement>
< site >
< id > redhatServer < /id >
< url > scp://HOST /var/www/html/site < /url >
</site >
< /distributionmanagement >

Note: HOST is the ip address to your webserver.

The id element must be a unique name to represent your site.
The url element must point to the location on your remote server where you want to deploy your site. Do note that scp:// is prefixed , this specifies that we are using ssh for tansfer.

2. Edit your settings.xml file ,which should be located under C:\Documents and Settings\YOUR_USERNAME\.m2 , by adding the following:

< server >
< id > redhatServer < /id >
< username > USERNAME_ON_REMOTE_SERVER < /username >
< password > PASSWORD_ON_REMOTE_SERVER < /password >
< filePermissions > 664 < /filePermissions >
< directoryPermissions > 775 < /directoryPermissions >
< /server >
< /servers >


USERNAME_ON_REMOTE_SERVER and PASSWORD_ON_REMOTE_SERVER should correspond to your username and password on the remote server (RedHat box).

3. Run mvn site site:deploy

This should now start creating your site and deploying it to your remote server.

4. If you get a nagging prompt that keeps coming like the following :

The authenticity of host '10.206.14.48' can't be established.
RSA key fingerprint is 14:93:e7:25:e5:cb:fe:d9:8b:3f

:c2:81:84:9f:b5:15.
Are you sure you want to continue connecting? (yes/no):

Then all you need to do is create a directory called .ssh under C:\Documents and Settings\YOUR_USERNAME\ .

You would require to use the mkdir .shh

Thats all that is required to perform the site deploy, hope it will help you out . I know this post is going to be boring for my not so techie readers :).

Saturday, December 23, 2006

Coding at home

The problem with working at home is that you are detached from your office tools and utilities. This inaccessibility is a major problem at times for example am so used to RAD 6.0 for development where almost every configuration is made via wizards that having to configure a web-app or webservice by hand or by writing a script makes me really lazy :P.

Finding the right opensource tools and being able to integrate it with your development environment is always a major headache. Thats the biggest problem with open source , you might get it free but as far as being able to get it working in your development environment you have to do the little tweaks and configurations yourself.

Its at this crucial moment that you find out that there is a lack of documentation for your new downloaded open source gizmo or that it actually runs on a newever version of JDK than you are using or it requires half a dozen of other stuffs to be installed before you can actually start doing anything with it.

I just can't thank the guys at Eclipse.org for making our lives ever so easy with the version 3.2+ onwards of my favorite IDE.Creating webservices and J2EE applications is really such a breeze with Eclipse Callisto. There are dozens of plugins which you can add on top of it to make your coding experience really worth while. I tend to think of coding with with Eclipse 3.2 as a really pleasurable moment these days just like racing my car at night :P.

As far as servers are concerned I really can not afford to buy a Weblogic or WebSphere server although in the latter case there is the Geronimo project . I think the server I use most at home is Apache Tomcat , can't find anything easier to install and manage than good old tomcat. The advantage with kitty is that there are hundreds of documentation sites for it , this can be pretty handy if you want to diagnose whats wrong with your server at times.

Building the codes is another story everyone has his own idea about how to make this happen. Some prefer using Ant which is right now on version 1.7 others prefer using Maven 1 or 2. This really doesn't matter if you are at home working alone .. as long as your codes get compiled and archived properly , you can use whatever makes you happy. Although I do definitively prefer Maven 2 because of the strong jar versioning emphasis , reusability and modularity of the build tool.

Frameworks allow you to develop faster however it doesn't mean that your code will perform better ..so be careful about thinking that everything new is good.. try to see how they do in terms of development and what added value they bring to performance. My favorite framework of the moment is spring . Don't know how long this framework will survive in the framework jungle but right now its the best.

But then before you do implement any piece of code there should be some kind of design work in terms of class diagrams and the layout of the architecture of your codes. Dia seems to be a neat alternative to Visio but I haven't been able to use it a lot , what I have been using on the other hand for some not so complicated diagrams is Gliffy.com. Since I blogged an entry on the Gliffy service many of my friends have actually started using it and are happy with it.

Do also check out Osalt.com which provides a nice directory of open source alternatives to commercial products.


Wednesday, November 22, 2006

JBuilder 2007 is out

The long awaited JBuilder 2007 has been released and unfortunately it is not yet available for download in the Borland JBuilder Downloads section.

Still you can always try out Foundation version of JBuilder 2005 which is absolutely free however it is a scrapped down version of the commercial IDE.



Before Eclipse ,JBuilder used to be the King of IDE's for Java Development but nowadays JBuilder has slowly slipped into a dark Era of unpopularity maybe due to its commercial nature and lack of plugins "a la Eclipse".Maybe this is why this time the core of JBuilder has been written upon the Eclipse platform :D.