您好,我正在尝试使用 jmf 创建一个简单的视频播放器。我认为我的代码没问题,但是当我执行它时,我得到了 NoPlayerException。这是播放器的代码:
package reproductor;
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;
/**
*
* @author pollyox16
*/
public class repropanel extends JPanel{
public repropanel(URL url){
setLayout(new BorderLayout());
Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
try{
createRealizedPlayer().
Component video= reproductor.getVisualComponent();
Component controles=reproductor.getControlPanelComponent();
if(video!=null){
add(video,BorderLayout.CENTER);
}
if (controles!=null){add(controles,BorderLayout.SOUTH);}
reproductor.start();//con esto arrancamos el reproductor.
} //end try
catch(NoPlayerException e3){
System.out.println("player not created");
}
catch (CannotRealizeException e){
System.out.println("player not realized");
}
catch (IOException e2){
System.out.println("io exception catch");
}
}
}
这是主应用程序的代码,它只创建一个 JFileChooser 并将 url 添加到播放器:这是主应用程序的代码:
package reproductor;
import java.net.URL;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
/**
*
* @author pollyox16
*/
public class Reproductor{
public static void main(String[] args) {
JFileChooser selectarchivo= new JFileChooser();
int resultado= selectarchivo.showOpenDialog(null);
if(resultado== JFileChooser.APPROVE_OPTION){
URL miurl=null;
try{
miurl=selectarchivo.getSelectedFile().toURI().toURL();
}//FINAL TRY
catch(Exception e){
System.out.println("error en el main");
}
if(miurl!=null){
JFrame ventana= new JFrame("pollyox16");
ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ventana.setSize(300,300);
repropanel mireproductor= new repropanel(miurl);
ventana.add(mireproductor);
ventana.setVisible(true);
}
}
}
}
编辑:这是异常堆栈跟踪:
javax.media.NoPlayerException: Cannot find a Player for :file:/C:/Users/Public/Videos/Sample%20Videos/Wildlife.wmv
at javax.media.Manager.createPlayerForContent(Manager.java:1412)
at javax.media.Manager.createPlayer(Manager.java:417)
at javax.media.Manager.createPlayer(Manager.java:332)
at javax.media.Manager.createRealizedPlayer(Manager.java:527)
at reproductor.repropanel.<init>(repropanel.java:34)
at reproductor.Reproductor.main(Reproductor.java:52)