Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Build a JavaFX Application It's About Time Sounds About Right

MediaException: Could not create Player!

When I attempt to run the app, then play the sound just as shown in the video, I get a MediaException. However, if I convert to wav, it runs and plays the sound just fine. Any ideas?

Exception in thread "Thread-4" com.sun.media.jfxmedia.MediaException: Could not create player!
    at com.sun.media.jfxmediaimpl.NativeMediaManager.getPlayer(NativeMediaManager.java:274)
    at com.sun.media.jfxmedia.MediaManager.getPlayer(MediaManager.java:118)
    at com.sun.media.jfxmediaimpl.NativeMediaAudioClipPlayer.play(NativeMediaAudioClipPlayer.java:319)
    at com.sun.media.jfxmediaimpl.NativeMediaAudioClipPlayer.clipScheduler(NativeMediaAudioClipPlayer.java:112)
    at com.sun.media.jfxmediaimpl.NativeMediaAudioClipPlayer.access$000(NativeMediaAudioClipPlayer.java:47)
    at com.sun.media.jfxmediaimpl.NativeMediaAudioClipPlayer$Enthreaderator.lambda$static$4(NativeMediaAudioClipPlayer.java:85)
    at java.lang.Thread.run(Thread.java:745)

5 Answers

Eric Schroeder
Eric Schroeder
19,894 Points

I've run into the same problem, not sure which OS you're using but I'm using Ubuntu 16.04. From my digging I think it's a compatibility issue between Java 8 and Ubuntu. Java wants to see libavcodec53 and libavformat53, 16.04 has libavcodec56 and libavformat56. I don't think you can downgrade these packages (I could be wrong) on newer ubuntu versions. I just use .wav file as you did, probably the easiest fix.

Check "JavaFX Media" at the bottom of this page.

Mike Hagedon
Mike Hagedon
16,478 Points

Thanks, Ubuntu 16.10 has the same issue. A .wav file worked!

William Thompson
William Thompson
4,580 Points

I had the same issue and I'm running Elementry OS based on ubuntu, using a wav file solves the problem

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Hmm... can you make sure that you are importing the right MediaClip class. Make sure it's from JavaFX, not the Applet one.

The same problem on Ubuntu

Jason Force
Jason Force
7,508 Points

Eric Schroeder Found a good link. I had the same problem on Ubuntu (Gnome) 17.04. However, instead of installing more packages (as the docs at that link suggest) I just converted the file to a .wav with VLC and that worked fine for me. Gotta love VLC.