【发布时间】:2022-11-02 05:53:55
【问题描述】:
我想使用MediaView 播放由Shinobi 媒体服务器生成的视频流和视频文件,但MediaView 似乎无法处理由Shinobi 生成的任何流或文件。
我正在使用 Java 18 和 JavaFX 19(我也尝试过旧版本)。
我有一个由 Shinobi here 生成的示例文件。
它在VLC中播放良好,这表明该文件具有以下属性:
编解码器:H264 - MPEG-4 AVC(第 10 部分)(avc1)
视频分辨率:1280x720
解码格式:平面 4:2:2 YUV 全比例
色度位置:剩下我已经向
MediaPlayer、MediaView和Media对象添加了错误处理程序,但是当我尝试播放文件时没有错误。有没有人知道为什么玩家不喜欢上面的文件?
有没有人成功地从 Shinobi 播放文件(它在封面下使用 FFMPEG。)?
它确实播放其他文件,例如:
https://coderslegacy.com/wp-content/uploads/2020/07/Pygame_Platformer-1.mp4";我希望视频可以正常播放,或者让播放器告诉我为什么它不能播放视频。
这是我的代码:
package com.example.videotester; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.GridPane; import javafx.scene.media.Media; import javafx.scene.media.MediaErrorEvent; import javafx.scene.media.MediaPlayer; import javafx.scene.media.MediaView; import javafx.stage.Stage; import java.io.File; public class HelloApplication extends Application { @Override public void start(Stage stage) throws Exception { Button button1 = new Button("Play"); Button button2 = new Button("Pause"); Button button3 = new Button("Stop"); String path = "C:/Users/Rob/Desktop/rlrO5DVBJS-2022-10-26T20-52-34.mp4"; File f = new File(path); path = f.toURI().toString(); // path="http://192.168.1.239:8080/532046fecc8da376f3f32f5518bad33b/videos/NUW6mXm9CF/rlrO5DVBJS/2022-10-26T14-32-07.mp4"; // path="http://192.168.1.239:8080/2921f1ca7204e640734709e29fc2033f/hls/NUW6mXm9CF/rlrO5DVBJS/s.m3u8"; // path="http://192.168.1.239:8080/2921f1ca7204e640734709e29fc2033f/h265/NUW6mXm9CF/rlrO5DVBJS/s.hevc"; // path="http://192.168.1.239:8080/2921f1ca7204e640734709e29fc2033f/mp4/NUW6mXm9CF/rlrO5DVBJS/s.mp4"; // path="http://192.168.1.239:8080/5ee9ca532fd17f860e3cef43a288b951/mjpeg/NUW6mXm9CF/rlrO5DVBJS"; //mjpeg // path="http://192.168.1.239:8080/f7fb8d581d5aab4ebb8732de13b61337/videos/NUW6mXm9CF/rlrO5DVBJS/2022-10-26T15-57-19.mp4"; // path="http://192.168.1.239:8080/5ee9ca532fd17f860e3cef43a288b951/videos/NUW6mXm9CF/rlrO5DVBJS/2022-10-27T19-49-31.mp4"; // path="http://192.168.1.239:8080/c6c8a86382548433c505d9e7cf7c2085/videos/NUW6mXm9CF/rlrO5DVBJS/2022-10-26T04-05-00.mp4"; // path="https://coderslegacy.com/wp-content/uploads/2020/07/Pygame_Platformer-1.mp4"; // path="https://www.dropbox.com/s/h1ky0he5dvclhkt/rlrO5DVBJS-2022-10-30T20-53-29.mp4?dl=0"; //Instantiating Media class // Media media = new Media(new File(path).toURI().toString()); //URL url = new URL(path); final Media media; final MediaPlayer mediaPlayer; MediaView mediaView = null; try { media = new Media(path); if (media.getError() == null) { media.setOnError(() -> System.out.println("media player error : " + media.getError())); try { mediaPlayer = new MediaPlayer(media); mediaPlayer.setAutoPlay(true); button1.setOnAction(e -> mediaPlayer.play()); button2.setOnAction(e -> mediaPlayer.pause()); button3.setOnAction(e -> mediaPlayer.stop()); mediaPlayer.setOnReady(() -> System.out.println("Video player ready")); if (mediaPlayer.getError() == null) { mediaPlayer.setOnError(() -> System.out.println("media player error : " + mediaPlayer.getError())); mediaView = new MediaView(mediaPlayer); mediaView.setOnError(mee -> System.out.println("media view error : " + t)); } else System.out.println("Error in media player: " + mediaPlayer.getError()); } catch (Exception mediaPlayerException) { System.out.println("media player exception " + mediaPlayerException); } } else System.out.println("Error media creating media " + media.getError()); } catch (Exception mediaException) { // Handle exception in Media constructor. System.out.println("Handle exception " + mediaException); System.exit(1); } GridPane layout = new GridPane(); layout.setHgap(10); layout.setVgap(10); layout.add(button1, 0, 0); layout.add(button2, 1, 0); layout.add(button3, 2, 0); layout.add(mediaView, 0, 1, 4, 1); Scene scene = new Scene(layout, 300, 200); stage.setTitle("Video Player Tester"); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(); }
【问题讨论】:
标签: javafx media-player mp4 h.264 shinobi