我在项目内的“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();
但这当然取决于应用程序的“当前”目录是什么,并且不能在 jar 文件中工作。
另一方面,VLCcan播放 zip(因此是 jar)文件中包含的媒体,其 MRL 看起来有点像您发布的内容。就像是:
zip://file.jar!/res/media/video.mp4
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)