如何在默认媒体播放器中使用 java(Netbeans IDE) 打开/播放视频

我正在尝试在 **Netbeans IDE (Java)** 中创建一个用于查看视频的应用程序。我不想创建媒体播放器来观看视频。我只想使用默认的媒体播放器。我的默认媒体播放器是 Windows 媒体播放器



千巷猫影
浏览 104回答 1
1回答

弑天下

您可以使用下面的代码使用 java 打开视频,但这仅适用于 ubuntu 或其他 Linux。您还可以检查您的操作系统并更改命令。对于 Windows,它只是文件名的绝对路径。public class Main{&nbsp; &nbsp; public static void main(String[] args)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; Runtime runtime = Runtime.getRuntime();&nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; runtime.exec("xdg-open <path+yourfilename>");&nbsp; &nbsp; &nbsp; &nbsp; } catch (IOException e) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.printStackTrace();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp;}用于窗户public class Main{&nbsp; &nbsp; public static void main(String[] args)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; Runtime runtime = Runtime.getRuntime();&nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String[] command = {"cmd.exe", "/k", "Start", "<path+yourfilename>"};&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Process p =&nbsp; runtime.exec(command);&nbsp; &nbsp; &nbsp; &nbsp; } catch (IOException e) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.printStackTrace();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java