June 19, 2016

How to Open Vlc using Java

01:37 Posted by DurgaSwaroop , , , No comments
Java is a very versatile programming language and so needless to say you can do a lot of things with it. Even if it is playing a video or audio using VLC!

So, what do you need to do this?
  • You obviously need Java installed on your system
  • You need VLC. Duh!!  (You can use just about any other player if you wish)
  • (Optional) Source code for this program from github
So, With that said, let's get started.

import java.io.IOException;
public class test {
    public static void main (String[] args) {
    try {
            System.out.println("Vlc Opening!");
            Runtime runTime = Runtime.getRuntime();
            String []command = { "vlc" , "D:\\java video.mp4"}; 
              //Replace the D:\\java... with the location of your file
            Process process = runTime.exec(command);
        } catch (IOException e){
Now, this is a modified version of the cod in the git repo. So, if you have downloaded it, just put both the files in the same folder and execute the ProgramRunner.java file.
Once, you execute this file ...... BAAM!! VLC is opened and will be playing the video. How cool is that..
So, how does this program work?
We are using two Java classes in this program. RunTime and Process.  The RunTime class allows out application to actually interface with the application (VLC in this case) where it is running.  And, the Process class helps us to perform input and output operations on a process.
So, with the help of these tow classes we are able to instruct the Operating System to open VLC and play a video for us.
So, that is all for this article.Stay tuned for more articles in the future.
As always, Stay curious and stay awesome!
Follow our blog posts . So that you won't miss any interesting posts
Follow us on our Facebook  page @ Fre Blogg 
Head over to my You Tube channel for a lot of interesting tutorials @ You Tube


Post a comment

Please Enter your comment here......