I am learning how to play videos using JMF from this link.
It throws:
Unable to handle format: MPEG, 1280x720, FrameRate=23.9, Length=1382400
Failed to realize: com.sun.media.PlaybackEngine@659a969b
Error: Unable to realize com.sun.media.PlaybackEngine@659a969b
javax.media.CannotRealizeException at
javax.media.Manager.blockingCall(Manager.java:2005) at
javax.media.Manager.createRealizedPlayer(Manager.java:528) at
com.mycompany.mavenproject3.MediaPanel.<init>(MediaPanel.java:33) at
com.mycompany.mavenproject3.MediaTest.main(MediaTest.java:47)
Could not realize media player
The MediaPanel:-
import java.awt.BorderLayout;
import java.awt.Component;
import java.io.IOException;
import java.net.URL;
import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.swing.JPanel;
public class MediaPanel extends JPanel
{
public MediaPanel( URL mediaURL )
{
setLayout( new BorderLayout() ); // use a BorderLayout
// Use lightweight components for Swing compatibility
Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );
try
{
// create a player to play the media specified in the URL
Player mediaPlayer = Manager.createRealizedPlayer( mediaURL );
// get the components for the video and the playback controls
Component video = mediaPlayer.getVisualComponent();
Component controls = mediaPlayer.getControlPanelComponent();
if ( video != null ){
add( video, BorderLayout.CENTER );
}
if ( controls != null ){
add( controls, BorderLayout.SOUTH );
}
mediaPlayer.start(); // start playing the media clip
} // end try
catch ( NoPlayerException noPlayerException )
{
System.err.println( "No media player found" );
} // end catch
catch ( CannotRealizeException cannotRealizeException )
{
System.err.println( "Could not realize media player" );
} // end catch
catch ( IOException iOException )
{
System.err.println( "Error reading from the source" );
} // end catch
} // end MediaPanel constructor
} // end class MediaPanel
My MediaTest.java file:
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
public class MediaTest{
public static void main( String args[] )
{
JFileChooser fileChooser = new JFileChooser();
int result = fileChooser.showOpenDialog( null );
if ( result == JFileChooser.APPROVE_OPTION ) // user chose a file
{
URL mediaURL = null;
try
{
mediaURL = fileChooser.getSelectedFile().toURL();
}
catch ( MalformedURLException malformedURLException )
{
System.err.println( "Could not create URL for the file" );
}
if ( mediaURL != null )
{
JFrame mediaTest = new JFrame( "Media Tester" );
mediaTest.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
MediaPanel mediaPanel = new MediaPanel( mediaURL );
mediaTest.add( mediaPanel );
mediaTest.setSize( 300, 300 );
mediaTest.setVisible( true );
}
}
}
}
My pom.xml file:-
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>mavenproject3</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>javax.media</groupId>
<artifactId>jmf</artifactId>
<version>2.1.1e</version>
</dependency>
<dependency>
<groupId>com.conviva.sdk</groupId>
<artifactId>conviva-mediaplayer-sdk</artifactId>
<version>2.145.0</version>
<type>aar</type>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
</project>
When I try to run the code, A popup appears which allows me to choose the video file I want to play, but when I choose the file, It says:- "Could not realize Media PLayer."
I am trying to play mpg format videos(mpg format is supported by JMF). I have to tried to play other video formats also like-mpeg,au etc but they are also not playing.
I have searched a lot on the web, while there are similar posts stating they were facing the same issue but there were not any clear solutions to this problem. I am attaching a pic of the issue I am facing.
Any help would be much appreciated. Thanks in Advance.
Note:- I am allowed to use only JMF for making this Video Player.
