Dimitris Sfounis
Dimitris Sfounis

Reputation: 2500

JavaFX - Media("File://derp") terminates with exception: MEDIA_INNACCESSIBLE

I'm trying to get a simple mp3 to run while my program runs, through this:

Media med = new Media("file://C:/Users/hariklia-elsa/workspace/PokerApp/src/intro.mp3");
MediaPlayer mPlayer = new MediaPlayer(med);
mPlayer.play();

But I'm running into problems. Running the program terminates with exception Exception in thread "main" MediaException: MEDIA_INACCESSIBLE : C, with reference to the first line of the code segment above, the one calling the Media() constructor.

I've had no previous experience with javafx or playing media in code, would anyone have any idea on why it would deem the file inaccessible? Am I doing anything simple incorrectly?

The file is, of course, fine. I can open it in a myriad different media players and it's fine.

Upvotes: 5

Views: 4115

Answers (1)

Sergey Grinev
Sergey Grinev

Reputation: 34528

This way it will work:

Media med = new Media("file:///C:/Users/hariklia-elsa/workspace/PokerApp/src/intro.mp3");

Note 3 slashes after file:.

Here is why: https://superuser.com/questions/352133/what-is-the-reason-that-file-urls-start-with-three-slashes-file-etc

Upvotes: 8

Related Questions