VLCJ - 从 "res" 文件夹播放视频在 eclipse 中效果很好,但不是从可执行 JAR 文件播放
VLCJ - playing a video from the "res" folder works great in eclipse, but not from the executable JAR file
我在项目的 "res/media" 文件夹中放置了一个 .MP4 视频。我可以使用这段代码轻松地在我的应用程序中从 eclipse 播放这个视频:
String url = getClass().getResource("/media/video.mp4").getFile();
url = new File(url).getPath();
showMedia(url); //the method that plays the video
我必须使用此代码,因为仅使用 URL url = getClass().getResource("/media/video.mp4");
会使 VLCJ 无法使用此 URL.
访问视频
创建可执行 JAR 文件时,我在控制台中收到以下错误:
libdvdnav: Using dvdnav version 5.0.0
libdvdread: Could not open D:\Desktop\file:\D:\Desktop\app.jar!\media\video.mp4 with libdvdcss.
libdvdread: Can't open D:\Desktop\file:\D:\Desktop\app.jar!\media\video.mp4 for reading
libdvdnav: vm: failed to open/read the DVD
[1644d0ac] filesystem access error: cannot open file D:\Desktop\file:\D:\Desktop\app.jar!\media\video.mp4 (Invalid argument)
[1644d0ac] main access error: File reading failed
[1644d0ac] main access error: VLC could not open the file "D:\Desktop\file:\D:\Desktop\app.jar!\media\video.mp4" (Invalid argument).
[1645643c] main input error: open of `file:///D:/Desktop/file%3A/D%3A/Desktop/app.jar%21/media/video.mp4' failed
[1645643c] main input error: Your input can't be opened
[1645643c] main input error: VLC is unable to open the MRL 'file:///D:/Desktop/file%3A/D%3A/Desktop/app.jar%21/media/video.mp4'. Check the log for details.
正在成功加载库,我什至可以播放 JAR 文件之外的任何视频。
有什么建议吗?
提前致谢。
媒体资源定位器 (MRL) 与 URL 不同。
您发布的日志显示了 VLC 试图打开的内容。信息部分是:
[1644d0ac] filesystem access error: cannot open file D:\Desktop\file:\D:\Desktop\app.jar!\media\video.mp4 (Invalid argument)
"D:\Desktop\file:\D:\Desktop\app.jar!\media\video.mp4"
显然不是有效的文件名?
所以这段代码是有缺陷的:
String url = getClass().getResource("/media/video.mp4").getFile();
这种没有 .getFile() 的东西通常用于从应用程序类路径加载资源。但是,当您尝试获取文件名时,情况并非如此。
你应该做类似的事情:
String mrl = new File("res/media/video.mp4").getAbsolutePath();
但这当然取决于您的应用程序的 "current" 目录,并且不会在 jar 文件中工作。
另一方面,VLC 可以 播放 zip(因此也是 jar)文件中包含的媒体,其 MRL 看起来有点像您发布的内容。类似于:
zip://file.jar!/res/media/video.mp4
我在项目的 "res/media" 文件夹中放置了一个 .MP4 视频。我可以使用这段代码轻松地在我的应用程序中从 eclipse 播放这个视频:
String url = getClass().getResource("/media/video.mp4").getFile();
url = new File(url).getPath();
showMedia(url); //the method that plays the video
我必须使用此代码,因为仅使用 URL url = getClass().getResource("/media/video.mp4");
会使 VLCJ 无法使用此 URL.
创建可执行 JAR 文件时,我在控制台中收到以下错误:
libdvdnav: Using dvdnav version 5.0.0
libdvdread: Could not open D:\Desktop\file:\D:\Desktop\app.jar!\media\video.mp4 with libdvdcss.
libdvdread: Can't open D:\Desktop\file:\D:\Desktop\app.jar!\media\video.mp4 for reading
libdvdnav: vm: failed to open/read the DVD
[1644d0ac] filesystem access error: cannot open file D:\Desktop\file:\D:\Desktop\app.jar!\media\video.mp4 (Invalid argument)
[1644d0ac] main access error: File reading failed
[1644d0ac] main access error: VLC could not open the file "D:\Desktop\file:\D:\Desktop\app.jar!\media\video.mp4" (Invalid argument).
[1645643c] main input error: open of `file:///D:/Desktop/file%3A/D%3A/Desktop/app.jar%21/media/video.mp4' failed
[1645643c] main input error: Your input can't be opened
[1645643c] main input error: VLC is unable to open the MRL 'file:///D:/Desktop/file%3A/D%3A/Desktop/app.jar%21/media/video.mp4'. Check the log for details.
正在成功加载库,我什至可以播放 JAR 文件之外的任何视频。
有什么建议吗?
提前致谢。
媒体资源定位器 (MRL) 与 URL 不同。
您发布的日志显示了 VLC 试图打开的内容。信息部分是:
[1644d0ac] filesystem access error: cannot open file D:\Desktop\file:\D:\Desktop\app.jar!\media\video.mp4 (Invalid argument)
"D:\Desktop\file:\D:\Desktop\app.jar!\media\video.mp4"
显然不是有效的文件名?
所以这段代码是有缺陷的:
String url = getClass().getResource("/media/video.mp4").getFile();
这种没有 .getFile() 的东西通常用于从应用程序类路径加载资源。但是,当您尝试获取文件名时,情况并非如此。
你应该做类似的事情:
String mrl = new File("res/media/video.mp4").getAbsolutePath();
但这当然取决于您的应用程序的 "current" 目录,并且不会在 jar 文件中工作。
另一方面,VLC 可以 播放 zip(因此也是 jar)文件中包含的媒体,其 MRL 看起来有点像您发布的内容。类似于:
zip://file.jar!/res/media/video.mp4