我试过了
public void makePlayer(File file) throws UnsupportedEncodingException
{
convertFileToFilename(file);
//filename1=filename1.replace("\\", "/");
//filename1=filename1.replace(" ", "+");
//JOptionPane.showMessageDialog(null,"1...file: "+filename);
filename=filename.toString();
//filename1=URLEncoder.encode(filename1, "UTF-8");
//JOptionPane.showMessageDialog(null,"2...file:"+filename);
media = new Media(filename);
//JOptionPane.showMessageDialog(null,"3...file:"+filename);
mediaPlayer=new MediaPlayer(media);
try{
SwingUtilities.invokeLater(new Runnable(){
public void run()
{
initAndShowGUI();
}
});
this.start();
}catch(Exception e){System.out.println(""+e);}
//JOptionPane.showMessageDialog(null,"4...file:"+filename);
view=new MediaView(mediaPlayer);
view.getMediaPlayer().play();
isplaying=true;
}
public void initAndShowGUI()
{
//JFrame jfram=new JFrame();
//jfram.add(fxPanel);
//jfram.setVisible(true);
mainPanel.add(fxPanel);
// mainPanel.update(null);
//fxPanel.setScene(scene);
mainPanel.setVisible(true);
Platform.runLater(new Runnable(){
public void run()
{
initFX(fxPanel);
}
});
}
public void initFX(JFXPanel fxp)
{
Group root = new Group();
/// Media media = new Media("F:\\video songs");
// MediaPlayer mediaPlayer = new MediaPlayer(media);
mediaPlayer.play();
MediaView mediaView = new MediaView(mediaPlayer);
root.getChildren().add(mediaView);
Scene scene = SceneBuilder.create().width(500).height(500).root(root)
.fill(Color.WHITE).build();
}
//Video play TRy//
public void start() throws Exception {
//primaryStage.setTitle("Media");
//primaryStage.setScene(scene);
//primaryStage.show();
}
//----------------------------------
public void convertFileToFilename(File file)
{
try {
filename=file.toURI().toURL().toExternalForm();
} catch (MalformedURLException ex) {
Logger.getLogger(MediaPlayerView.class.getName()).log(Level.SEVERE, null, ex);
}
}
我从上周开始工作。有什么简单的方法可以在 javafx 中播放视频吗?或任何参考?