JEditorPane 嵌入 HTML object 標籤失敗。| 方案 | 優點 | 缺點 | 是否需原生庫 |
|---|---|---|---|
| Xuggler (已停止維護) | 純 Java 解碼,支援 FLV | 專案已歸檔,效能一般 | 否 (含原生碼打包在 jar) |
| JavaFX MediaPlayer (嵌入 Swing) | 官方支援,硬體加速,無額外依賴 | 需 JDK 8+,啟動較重 | 否 (模組化內建) |
| VLCJ (libvlc 封裝) | 格式支援最全,穩定 | 必須安裝 VLC 播放器/部署 libvlc.dll | 是 |
| FFmpeg + JNA 自行封裝 | 完全可控 | 開發成本極高 | 是 |
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>17</version>
</dependency>
// Swing 中嵌入
JFXPanel fxPanel = new JFXPanel();
Platform.runLater(() -> {
MediaPlayer player = new MediaPlayer(new Media(getClass().getResource("/video.flv").toString()));
MediaView mediaView = new MediaView(player);
Scene scene = new Scene(new StackPane(mediaView));
fxPanel.setScene(scene);
player.play();
});
frame.add(fxPanel, BorderLayout.CENTER);
--module-path 或使用 javafx-maven-plugin 打包。參考討論:CSDN 相關主題