I'm trying to create a JavaFX 2 Media Instance with a relative path (in Eclipse). I've tried it by writing this:
Media media= new Media("file://test.flv");
This gives me a MediaException of type MEDIA_INACCESSIBLE. The file I'm trying to load is located in my eclipse project root folder.
I am aware of the answer to this question How to target a file (a path to it) in Java/JavaFX but this only covers loading a file with an absolute path or as a resource.
Thanks
1. if you want to load media from path relative to your .java/.class file you have to use resource loading. Nobody else can be sure about their location.
Just add .toExternalForm() if you don't like raw resources for some reason:
Media media= new Media(getClass().getResource("test.flv").toExternalForm());
2. if you want to load media relative to workdir of your application you can try next:
Media media = new Media(new File("test.flv").toURI().toString());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With