视频无法启动

时间:2016-01-10 00:25:23

标签: javafx video media-player media

我是Java的初学者。我正在尝试使用JavaFX创建一个视频播放器,但在运行代码后,视频无法启动。但是,控制台没有显示任何错误。

这是代码:

package application;

import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;

public class Player extends BorderPane {

Media media;
MediaPlayer player;
MediaView view;
Pane mpane;

public Player(String file){

    if (file == null)
        return;
    media = new Media(file);
    player = new MediaPlayer(media);
    view = new MediaView(player);
    mpane = new Pane();

    mpane.getChildren().add(view);      
    setCenter(mpane);       
    player.play();

    }   
}

主要课程:

    package application;

import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {

        Player player = new Player("file:///D:/2013.flv");
        Scene scene = new Scene(player, 720, 480, Color.BLACK);
        primaryStage.setScene(scene);
        primaryStage.show();

    }

    public static void main(String[] args) {
        launch(args);
    }
}

任何人都可以帮助我吗?

0 个答案:

没有答案