简体   繁体   English

媒体:在 JAR 中播放 WAV 文件

[英]Media: Play WAV file inside JAR

There is only one constructor of the Media -class: public Media(java.lang.String source) see http://docs.oracle.com/javafx/2/api/javafx/scene/media/Media.html#Media%28java.lang.String%29 Media -class 只有一个构造函数: public Media(java.lang.String source)参见http://docs.oracle.com/javafx/2/api/javafx/scene/media/Media.html#Media% 28java.lang.String%29

This constructor gets a URI as string.此构造函数以字符串形式获取 URI。 I have a JavaFX project and put a WAV file inside this project.我有一个 JavaFX 项目,并在该项目中放置了一个 WAV 文件。 When I deploy the project as a JAR, I can see (with 7-Zip for example), that the WAV file is also exported.当我将项目部署为 JAR 时,我可以看到(例如使用 7-Zip),WAV 文件也被导出。 There is no problem to get the content with获取内容没有问题

MyApplicationClass.class.getResourceAsStream("/resources/test.wav").

But what is the correct URI to refer this WAV file inside the deployed JAR for the Media constructor?但是,在已部署的 JAR 中为Media构造函数引用此 WAV 文件的正确 URI 是什么? The URI URI

new Media("jar:.!/resources/test.wav")

doesnt work.不起作用。 The URI "jar:resources/test.wav" fails too (becouse there is no reference to the JAR file). URI "jar:resources/test.wav"失败了(因为没有引用 JAR 文件)。

Does anybody have an idea about the correct URI?有人知道正确的URI吗?

try this one out试试这个

new Media(MyApplicationClass.class.getResource("/resources/test.wav").toURI().toString())

Media accepts jar uris so it should work fine媒体接受 jar uris 所以它应该可以正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM