在JavaFX8中播放视频 [英] Playing Video in JavaFX8

查看:255
本文介绍了在JavaFX8中播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JavaFX的新手,我正在使用在应用程序开始时播放视频(.MP4)的应用程序,但是,我似乎无法使其工作!请告诉我我的代码有什么问题:

I am new to JavaFX and Im currently working with an application that plays a video(.MP4) at the beginning of the application, however, I cant seem to make it work! Please tell me what's wrong with my code:

import java.io.File;
import javafx.geometry.Pos;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.text.Text;

public class NoConnection {

    private StackPane root;

    public NoConnection(){
        Media media = null;
        try{
            File video = new File("video.mp4");
            String url = video.toURI().toURL().toString();
            System.out.println("URL: "+url);
            media = new Media(url);
        }catch(Exception e){
        System.err.println(e.toString());
    }
        MediaPlayer player = new MediaPlayer(media);
        player.play();
        MediaView mediaView = new MediaView(player);

        root = new StackPane();
        root.setAlignment(Pos.CENTER);
        root.setStyle("-fx-background-color : white;");
        root.getChildren().add(mediaView);
    }

    public StackPane getLayout(){
        return root;
    }

}

顺便说一下,我正在运行Windows XP!

By the way, Im running Windows XP!

这是完整的错误:

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/11461388.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/31501478.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$38/29531133.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)


推荐答案

以下是答案:

JavaFX SDK支持的平台上的媒体堆栈支持FLV容器。以这种格式编码的单个电影可在支持的平台上无缝工作。服务器端需要标准的FLV MIME设置才能启用媒体流。

The FLV container is supported by the media stack on the platforms supported by the JavaFX SDK. A single movie encoded in this format works seamlessly on supported platforms. Standard FLV MIME settings are required on the server side to enable media streaming.

JavaFX支持的所有操作系统也支持MPEG-4多媒体容器SDK。在Mac OS X和Windows 7平台上,播放功能无需其他软件。但是,Linux操作系统和Windows 7之前的Windows版本需要安装随时可用的第三方软件包,如JavaFX系统要求中所述。 AAC和H.264 / AVC解码具有某些依赖于平台的限制,如JavaFX发行说明中所述。

某些音频和视频压缩类型的解码依赖于特定于操作系统的媒体引擎。 JavaFX媒体框架不会尝试处理这些本机引擎支持的所有多媒体容器格式和媒体编码。相反,该框架试图在支持JavaFX的所有平台上提供等效且经过良好测试的功能。

Decoding of some audio and video compression types relies on operating system-specific media engines. The JavaFX media framework does not attempt to handle all multimedia container formats and media encodings supported by these native engines. Instead, the framework attempts to provide equivalent and well-tested functionality across all platforms on which JavaFX is supported.

这篇关于在JavaFX8中播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆