使用JMF播放视频文件 [英] Playing video file using JMF
本文介绍了使用JMF播放视频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用JMF播放视频。我也在Ubuntu中使用netbeans。没有在程序中出现任何错误。但我不能打开视频。相反,我得到一个错误消息为没有找到媒体播放器的对话框。
实际上我编写的程序就像我点击按钮5,视频文件必须播放通过使用JFilechooser选择文件。
这是我的代码
I am trying to play a video using JMF. Also I am using netbeans in Ubuntu. Not getting any error in the program. but I cant open video. Instead am getting a dialog box having error message as "No media Player found".
Actually I have written program like when I click button5, the video file has to play by selecting file using JFilechooser.
Here is my code
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
openMedia();
} catch (IOException ex) {
//Logger.getLogger(SoundBytePlaying.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void openMedia() throws IOException{
JFileChooser fileChooser = new JFileChooser();
int result = fileChooser.showOpenDialog(jButton5);
if(result == JFileChooser.APPROVE_OPTION)
{
URL mediaURL = null;
try{
mediaURL = fileChooser.getSelectedFile().toURL();
}catch(MalformedURLException malformedURLException){
JOptionPane.showMessageDialog(null, "Could not create URL for the file");
}
if(mediaURL != null){
showVideo(mediaURL); //some error here**
System.out.println("camera displaying..");
}
}
}
public void showVideo(URL mediaURL){
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 ); //add video component
if ( controls != null )
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 ex){
JOptionPane.showMessageDialog(null, "Could not realize media player.");
} //end catch
catch (IOException iOException ){
JOptionPane.showMessageDialog(null, "Error reading from the source.");
} //end catch
}
请指导我。
谢谢。
Please Guide me.
Thank you.
推荐答案
请不要重新发布,这是一个完全重复的如何使用jmf.jar链接视频 [ ^ ]。
Please do not repost, this is an exact duplicate of How do I link video using jmf.jar[^].
这篇关于使用JMF播放视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文