b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

从“res”播放视频文件夹在eclipse中工作得很高,但不是从可执行文件JAR文件(2)

电脑杂谈  发布时间:2019-08-24 21:08:39  来源:网络整理

这些库正在成功读取,我甚至可以播放我的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()通常用于从应用程序加载资源类路径。但是视频播放器jar版,当您尝试获得文件名时,情况并非如此。

您需要执行以上操作:

  String mrl = new File(“res / media / video.mp4”)。getAbsolutePath(); 

但这当然取决于您的应用程序的“当前”目录,而不会在一个jar文件中工作。

另一方面,VLC 可以播放包含在zip(和显然jar)文件内的外媒,并使用MRL看起来有点像你发贴。如下:

  zip://file.jar!/res/media/video.mp4 

本文地址:IT屋 VLCJ - 从“res”播放视频文件夹在eclipse中工作得很高,但不是从可执行文件JAR文件

问 题

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:

哈弗h5经典版视频播放_李宗瑞视频播放手机版下载_视频播放器jar版

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

官方微信

扫一扫关注IT屋

微信公众号搜索 “ IT屋 ” ,选择关注与百万开发者在一起


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/bofangqi/article-120452-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...