Reputation: 63
I want to play a video inside a Jframe and am attaching it to a jpanel (jPanel1) where it must play. It keeps saying:
"Error reading from the source."
And I feel that my media URL is right. It's a small MP4 video.
This is my code:
public void Player() {
try{
//create a player to play the media specified in the URL
Player mediaPlayer = Manager.createRealizedPlayer(new URL("C:\\Users\\Michael\\Downloads\\mike.jar"));
Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
//get the components for the video and the playback controls
Component video = mediaPlayer.getVisualComponent();
Component controls = mediaPlayer.getControlPanelComponent();
if ( video != null )
jPanel1.add( video, BorderLayout.CENTER ); //add video component
if ( controls != null )
jPanel1.add( controls, BorderLayout.SOUTH ); //add controls
mediaPlayer.start(); //start playing the media clip
} //end try
catch ( NoPlayerException noPlayerException ){
JOptionPane.showMessageDialog(null, "No media player found");
} //end catch
catch ( CannotRealizeException cannotRealizeException ){
JOptionPane.showMessageDialog(null, "Could not realize media player.");
} //end catch
catch ( IOException iOException ){
JOptionPane.showMessageDialog(null, "Error reading from the source.");
} //end catch
Upvotes: 0
Views: 6822
Reputation: 25954
new URL("C:\\Users\\Michael\\Downloads\\mike.jar")
This is not how you want to be creating a URL that points to a local file. Use
new File(path).toURI().toURL()
Upvotes: 2