4

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

Community
  • 1
  • 1
Nikos P.
  • 75
  • 2
  • 8

1 Answers1

5

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());
Sergey Grinev
  • 34,078
  • 10
  • 128
  • 141