如何在 JavaFX 中访问我的计算机上的本地媒体文件?
如何在 JavaFX 中访问我的计算机上的本地媒体文件?
以下是我尝试过的网址:
C:/PROJECT/videos/on2tm_352.flv
file:///C://PROJECT/videos/on2tm_352.flv
(在某些站点中建议忘记在哪里)
但是,当我将媒体文件放入项目的文件夹中并使用它访问它时,它确实会播放{__DIR__}/on2tm_352.flv
注意:没有输出任何异常和错误。屏幕一片空白。
使用 KLite Codec 583 Mega、JavaFX 1.2、Netbeans 6.8
How to access local media file on my computer in JavaFX?
Here are the urls I tried:
C:/PROJECT/videos/on2tm_352.flv
file:///C://PROJECT/videos/on2tm_352.flv
(suggested in some site forgot where)
It does play however, when I put the media file inside the project's folder and access it using {__DIR__}/on2tm_352.flv
Note: There are no exceptions and errors outputted. The screen is just blank.
KLite Codec 583 Mega, JavaFX 1.2, Netbeans 6.8 are used
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
它现在对我来说正在工作:
我几分钟前测试过......
或者类似的东西:
稍后见=D
It is working right now for me:
I tested it a few minutes ago....
or something like that:
See you later =D
试试这个:
Try this out:
通过向媒体提供他们的网址?
请注意,过去曾报告过一些路径中空格的问题,我不知道是否仍然如此。
[在原始消息编辑后进行编辑(URL 示例)]
第一行不是 URL,而是路径。显然,媒体播放器接受路径作为 URL,但 ImageView 的情况并非如此,因此最好严格一些。
第二行是正确的。
第三行有一个潜在的问题:
__DIR__
变量已经有一个终端斜杠,所以你不应该添加它,即。改为编写{__DIR__}on2tm_352.flv
。不确定这是否是问题所在(我还没有使用太多视频),但值得尝试。请注意,一旦项目打包,此类 URL(基于 __DIR__ )将指向 jar 文件内部。
在 JavaFX 1.2 中这是可以的,但由于某些奇怪的原因,他们选择在 1.3 中禁止此类访问。
By giving their URL to the Media?
Note that some issues with spaces in paths have been reported in the past, I don't know if it is still true.
[EDIT following original message edit (URL examples)]
First line isn't an URL, it is a path. Apparently the media player accepts paths as URL, but that's not the case for ImageView, though, so it is better to be strict.
Second line is correct.
Third line have a potential issue:
__DIR__
variables has already a terminal slash, so you should not add it, ie. write{__DIR__}on2tm_352.flv
instead. Not sure if that's the issue (I haven't used much video yet) but worth trying.Note that such URL (based on
__DIR__
) will point inside a jar file once the project is packaged.It is OK in JavaFX 1.2, but for some odd reason, they chose to disallow such access in 1.3.
我发现使用磁盘文件执行以下操作更容易。这让我的弱智不再需要确定“file:”url 的所有规则:
我避免对媒体使用
{__DIR__}
,因为它可以指向“jar:”URL,并且不再支持该 URL。 JavaFX 1.3 中的媒体位置。I have found it easier to do the following with disk files. This relieves my feeble brain of determining all the rules for "file:" urls:
I avoid using
{__DIR__}
for media as it can point to a "jar:" URL and that is no longer supported for media locations in JavaFX 1.3.你们只需将文件的路径指定为 URI 路径即可:
根本不需要实例化文件。
You guys just have to specify the file's path as an URI path:
It's not required to instantiate a File at all.