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


Question

Quick question, gents:

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.

1
5
10/8/2014 8:08:34 PM

Accepted Answer

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

7
3/20/2017 10:04:20 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon