VLCJ - playing a video from the “res” folder works great in eclipse, but not from the executable JAR file

情到浓时终转凉″ 提交于 2019-12-02 02:37:10

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!