Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Media: Play WAV file inside JAR

Tags:

java

javafx-2

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?

like image 539
Vertex Avatar asked Mar 27 '13 14:03

Vertex


1 Answers

try this one out

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

Media accepts jar uris so it should work fine

like image 155
Ion Cojocaru Avatar answered Nov 06 '22 09:11

Ion Cojocaru