Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
306 views
in Technique[技术] by (71.8m points)

java - 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

This constructor gets a URI as string. I have a JavaFX project and put a WAV file inside this project. When I deploy the project as a JAR, I can see (with 7-Zip for example), that the WAV file is also exported. 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? The 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).

Does anybody have an idea about the correct URI?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try this one out

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

Media accepts jar uris so it should work fine


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...