
Google Facebook Youtube 科学上网》戳这里《
百度翻译此文有道翻译此文
问 题
i have an .MP4 video placed in the "res/media" folder inside my project. I can easily play this video in my application from eclipse using this piece of code:
String url = getClass().getResource("/media/video.mp4").getFile();
url = new File(url).getPath();
showMedia(url); //the method that plays the video
i had to use this code because using only URL url = getClass().getResource("/media/video.mp4"); makes VLCJ can't access the video using this URL.
When creating the executable JAR file, i get these errors in the console:
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.
The libraries are being successfully loaded, and i can even play any video that is outside my JAR file.
Any suggestions?
And thanks in advance.
解决方案
A Media Resource Locator (MRL) is not the same as a URL.
The log you posted shows what VLC is trying to open. The informative part is:
[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" is clearly not a valid filename?
So this code is flawed:
String url = getClass().getResource("/media/video.mp4").getFile();
This type of thing, without the .getFile(), is usually used to load resources from the application classpath. That's not the case here though when you try and get the file name.
You should just do something like:
String mrl = new File("res/media/video.mp4").getAbsolutePath();
But that of course depends on what is the "current" directory for your application, and won't work inside a jar file.
On the other hand, VLC can play media contained inside zip (and therefore jar) files, with an MRL that looks a little bit like what you posted. Something like:
zip://file.jar!/res/media/video.mp4
本文地址:IT屋 VLCJ - playing a video from the "res" folder works great in eclipse, but not from the executable JAR file
问 题
我有一个.MP4视频放在我的项目中的“res / media”文件夹中。我可以使用这段代码从eclipse中轻松播放这个视频:
String url = getClass()。getResource “/media/video.mp4”)的GetFile();
url = new File(url).getPath();
showMedia(url); //播放视频的方法
我不得不使用这段代码,因为只使用 URL url = getClass()。getResource(“/ media / video.mp4”); 使VLCJ无法使用此URL访问视频。
创建可执行JAR文件时,我在控制台中收到以下出错:
libdvdnav:使用dvdnav版本5.0 .0
libdvdread:无法使用libdvdcss打开D:\Desktop\file:\D:\Desktop\app.jar!\media\video.mp4。
libdvdread:无法打开D:\Desktop\file:\D:\Desktop\app.jar!\media\video.mp4读
libdvdnav:vm:无法打开/读取DVD
[1644d0ac]文件系统访问错误:无法打开文件D:\Desktop\file:\D:\Desktop\app.jar!\media\video。 mp4(参数无效)
[1644d0ac]主访问错误:文件读取失败
[1644d0ac]主访问错误:VLC无法打开文件“D:\Desktop\file:\D: \Desktop\app.jar!\media\video.mp4“(参数无效)。
[1645643c]主输入错误:打开`file:/// D:/Desktop/file%3A/D%3A/Desktop/app.jar%21/media/video.mp4'失败
[1645643c]主输入错误:您的输入无法打开
[1645643c]主输入错误:VLC无法打开MRL文件:/// D:/ Desktop / file%3A / D% 3A /桌面/ app.jar%21 /媒体/ video.mp4' 。检查日志的详细信息。
这些库正在成功读取,我甚至可以播放我的JAR文件外的任何视频。
任何建议?
提前感谢。
解决方案
媒体资源定位器(MRL)与URL不同
您公布的日志显示了VLC正试图开启信息部分是:
[1644d0ac]文件系统访问错误:无法打开文件D:\Desktop\file:\ D:\Desktop\app.jar!\media\video.mp4(参数无效)
“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文件中工作。
另一方面,VLC 可以播放包含在zip(和显然jar)文件内的外媒视频播放器jar版,并使用MRL看起来有点像你发贴。如下:
zip://file.jar!/res/media/video.mp4
本文地址:IT屋 VLCJ - 从“res”播放视频文件夹在eclipse中工作得很高,但不是从可执行文件JAR文件

扫一扫关注IT屋
微信公众号搜索 “ IT屋 ” ,选择关注
与百万开发者在一起
官方交流群:
Google Facebook Youtube 科学上网》戳这里《
百度翻译此文有道翻译此文
问 题
我有一个.MP4视频放在我的项目中的“res / media”文件夹中。我可以使用这段代码从eclipse中轻松播放这个视频:
String url = getClass()。getResource “/media/video.mp4”)的GetFile();
url = new File(url).getPath();
showMedia(url); //播放视频的方法
我不得不使用这段代码,因为只使用 URL url = getClass()。getResource(“/ media / video.mp4”); 使VLCJ无法使用此URL访问视频。
创建可执行JAR文件时,我在控制台中收到以下出错:

libdvdnav:使用dvdnav版本5.0 .0
libdvdread:无法使用libdvdcss打开D:\Desktop\file:\D:\Desktop\app.jar!\media\video.mp4。
libdvdread:无法打开D:\Desktop\file:\D:\Desktop\app.jar!\media\video.mp4读
libdvdnav:vm:无法打开/读取DVD
[1644d0ac]文件系统访问错误:无法打开文件D:\Desktop\file:\D:\Desktop\app.jar!\media\video。 mp4(参数无效)
[1644d0ac]主访问错误:文件读取失败
[1644d0ac]主访问错误:VLC无法打开文件“D:\Desktop\file:\D: \Desktop\app.jar!\media\video.mp4“(参数无效)。
[1645643c]主输入错误:打开`file:/// D:/Desktop/file%3A/D%3A/Desktop/app.jar%21/media/video.mp4'失败
[1645643c]主输入错误:您的输入无法打开
[1645643c]主输入错误:VLC无法打开MRL文件:/// D:/ Desktop / file%3A / D% 3A /桌面/ app.jar%21 /媒体/ video.mp4' 。检查日志的详细信息。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/bofangqi/article-120452-1.html
下次不买了
弄个破渔网让它拖着不是很好么