Overview Of Video Player In Java

Posted By : Yasir Zuberi | 31-May-2018

Introduction:-

 

It's quite hard to make a simple video player in Java. This requires a basic understanding of the syntax of the language, the ability to work with frameworks and problem-solving. A very important solution to a problem is two errors in the program.

In Java, it is easy to create an application. But the two hardest tasks make it work and work well quickly and accurately.

Why are you doing a media player with Java now?
There are many tools to make the video player use Java. FFMPEG library in Java could help a lot with codecs, JMF stands for Java Media Framework, Android MediaPlayer class,native Swing, VLCJ (Java links to VideoLAN) and others.

 

Consider the realization of the video player in Java using the Java Media Framework.
In itself, JMF cannot play modern video. It requires a compliment that recognizes different formats. In fact, it is useless without them.
There were many enthusiasts who added these additions. But after a while, support and updates for these additions were impossible or almost supported.

JMF (stable)
License: SCSL
Compatibility: All platforms compatible with Java
Multiplatform: yes

 

JMF download is represented by two types: platform dependent and multiplatform version. Sun Company offers platform versions that are specific to Solaris and Windows. (The Linux version of Blackdown is also available).
You can find the JMF API on the Oracle website or your favorite search engine.
There are 4 jar files in the file to add to the project.
It's easy if you work in STS, therefore, to add files to your project, simply right-click on the project name and then choose to Create Path-Configure Compile Path-Add External JARs.

Playing media files through JMF(Java Media Framework) is a simple operation. Manager and Player are the key classes and a leader set of methods createPlayer (), each player back. When you have created a player, it tells you to start playback.

 

The player is a type of controller and the drivers allow you to register a ControllerListener. ControllerListener contains a single method: public void controllerUpdate (ControllerEvent event). This method is used to capture different events with media data, for example. To get to the end of the video data, exit the download, start, and end of the multimedia data playback.

 

Here is the code of video player:-

 

package videoPlayer;
 
import java.awt.Dimension;
import javax.swing.*;
import javax.media.bean.playerbean.MediaPlayer;
 
class VideoPlayer extends JFrame{
    MediaPlayer player;//our video player
 
    public VideoExample(String path){
        super("Simple video player");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(new Dimension(640,480));//set the player window size
        player = new MediaPlayer();
        player.setMediaLocation("file:///" + path); 
        player.setPlaybackLoop(false);//repeat the video file
        player.prefetch(); 
        add(player);
        player.start(); - start the player
        setVisible(true);
    }
 
    public static void main(String []args){
        VideoExample ve = new VideoExample(filePath);
    }
}

 

 

You must add the jffmpeg-1.1.0.jar library containing codecs to play video and audio formats in the project to solve the problem.

Thanks,

Yasir

About Author

Author Image
Yasir Zuberi

Yasir is Lead Developer. He is a bright Java and Grails developer and have worked on development of various SaaS applications using Grails framework.

Request for Proposal

Name is required

Comment is required

Sending message..