Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 986
Dimitris Sfounis Avatar asked Dec 24 '12 20:12

Dimitris Sfounis


1 Answers

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

like image 183
Sergey Grinev Avatar answered Nov 02 '22 16:11

Sergey Grinev