Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Playing sound file not working

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Playing sound file not working

    Hey all,

    I tried out this video here: https://www.youtube.com/watch?v=ameD1ocbn9s

    Now I want to change this, to play the file directly with java, with the javafx player:

    String source = f.toURI().toString();
    Media media = null;
    media = new Media(source);
    MediaPlayer mediaPlayer = new MediaPlayer(media);
    mediaPlayer.play();

    But I get an "Toolkit not initialized" error. I cant figure out why this is happening?


  2. #2
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Playing sound file not working

    I find out why this exception is thrown:
    JavaFX performs "hidden" initialization on start. Running MediaPlayer doesn't trigger initialization.

    The easiest ways to trigger it are:

    have Application.launch() executed
    have Application based program being run from jar packaged by fx ant tasks (e.g. built from Netbeans JavaFX project)
    have JFXPanel started
    So which is the best way?

Similar Threads

  1. playing sound by pressing key
    By pebri in forum Android Development
    Replies: 0
    Last Post: March 5th, 2013, 12:10 PM
  2. Playing sound each time mouse is clicked (not working)
    By BestSanchez in forum What's Wrong With My Code?
    Replies: 0
    Last Post: August 24th, 2012, 10:51 PM
  3. pause while playing sound
    By huddo in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: August 23rd, 2012, 09:33 PM
  4. Playing sound in an applet
    By Skyhigh32 in forum Java Theory & Questions
    Replies: 1
    Last Post: June 3rd, 2011, 08:41 AM
  5. playing sound using java
    By sdhilipan89 in forum Java Applets
    Replies: 6
    Last Post: March 25th, 2010, 09:59 AM