7 Replies Latest reply on Apr 20, 2011 2:44 PM by captfoss

    Failed to realize exception

    855769
      I'm running the following code:
      package mediastreamer;

      import javax.media.*;

      import java.io.File;
      import java.io.IOException;
      import java.net.URL;
      import java.net.MalformedURLException;

      /**
      * A Simple audio player class for playing audio files using JMF.
      * This class is able to play any audio formats that the JMF supports,
      * including (but not limited to:) mp3, rmf, aiff, wav, au, and midi.
      * See java.sun.com/products/java-media/jmf/2.1.1/formats.html for
      * more information on supported file formats in JMF.
      */
      public class MediaStreamer {

      /**
      * The Player object which is used to play an audio file.
      */
      private Player audioPlayer = null;

      /**
      * Creates a new instance of the simple audio player.
      * @param url The url of the audio file to play.
      * @throws IOException Indicates a problem opening the file.
      * @throws NoPlayerException JMF was unable to create a player for
      * the file type specified.
      * @throws CannotRealizeException Indicates a problem in realizing the
      * player.
      */
      public MediaStreamer(URL url) throws IOException, NoPlayerException,
      CannotRealizeException {
      audioPlayer = Manager.createRealizedPlayer(url);
      }

      /**
      * Creates a new instance of the simple audio player.
      * @param file The audio file to play.
      * @throws IOException Indicates a problem opening the file.
      * @throws NoPlayerException JMF was unable to create a player for
      * the file type specified.
      * @throws CannotRealizeException Indicates a problem in realizing the
      * player.
      */
      public MediaStreamer(File file) throws IOException, NoPlayerException,
      CannotRealizeException {
      this(file.toURI().toURL());
      }

      /**
      * Plays the audio file.
      */
      public void play() {
      audioPlayer.start();
      }

      /**
      * Stops and closes the audio file.
      */
      public void stop() {
      audioPlayer.stop();
      audioPlayer.close();
      }

      /**
      * Prints a usage message to System.out for how to use this class
      * through the command line.
      */
      public static void printUsage() {
      System.out.println("Usage: java MediaStreamer audioFile");
      }

      /**
      * Allows the user to run the class through the command line.
      * Only one argument is allowed, which is the file name of
      * the audio file.
      */
      public static void main(String[] args) {
      try {
      if (args.length == 1) {
      /* Creates and uses a file reference for the audio file,
      if a url reference is desired, then this line needs to
      change.
      */
      File audioFile = new File(args[0]);
      MediaStreamer player = new MediaStreamer(audioFile);

      System.out.println();
      System.out.println("-> Playing file '" +
      audioFile.getAbsolutePath() + "'");
      System.out.println(" Press the Enter key to exit");
      player.play();

      // wait for the user to press Enter to proceed.
      System.in.read();
      System.out.println("-> Exiting");
      player.stop();
      } else {
      printUsage();
      }
      } catch (Exception ex) {
      ex.printStackTrace();
      }

      System.exit(0);
      }
      }

      and I'm getting the following error:

      Unable to handle format: mpeglayer3, 44100.0 Hz, 16-bit, Stereo, LittleEndian, Signed, 16000.0 frame rate, FrameSize=32768 bits
      Failed to realize: com.sun.media.PlaybackEngine@528acf6e
      Error: Unable to realize com.sun.media.PlaybackEngine@528acf6e
      javax.media.CannotRealizeException
      at javax.media.Manager.blockingCall(Manager.java:2005)
      at javax.media.Manager.createRealizedPlayer(Manager.java:528)
      at mediastreamer.MediaStreamer.<init>(MediaStreamer.java:35)
      at mediastreamer.MediaStreamer.<init>(MediaStreamer.java:49)
      at mediastreamer.MediaStreamer.main(MediaStreamer.java:88)

      What's causing the problem?
        • 1. Re: Failed to realize exception
          captfoss
          Unable to handle format: mpeglayer3, 44100.0 Hz, 16-bit, Stereo, LittleEndian, Signed, 16000.0 frame rate, FrameSize=32768 bits
          What's causing the problem?
          The fact that JMF doesn't handle MP3s without the optimal MP3 plugin?

          http://www.oracle.com/technetwork/java/javase/download-137625.html
          • 2. Re: Failed to realize exception
            855769
            I ran the extractor for windows and then ran my program and I got the same error.

            I tried a wave file too and got the following error.

            Unable to handle format: ima4/ms, 22050.0 Hz, 4-bit, Mono, Unsigned, 11100.0 frame rate, FrameSize=4096 bits
            Failed to prefetch: com.sun.media.PlaybackEngine@204f80d6
            Error: Unable to prefetch com.sun.media.PlaybackEngine@204f80d6
            • 3. Re: Failed to realize exception
              captfoss
              Try some different MP3 files, maybe that one is funky.

              And your wav file is definately funky. You should use a WAV file that uses linear PCM encoding (a "normal" one) rather than an encoded WAV file.
              • 4. Re: Failed to realize exception
                855769
                I downloaded a random wav file off the internet and I get this error:
                Unable to handle format: LINEAR, 44100.0 Hz, 16-bit, Mono, LittleEndian, Signed, 88200.0 frame rate, FrameSize=16 bits

                Failed to prefetch: com.sun.media.PlaybackEngine@204f80d6
                Error: Unable to prefetch com.sun.media.PlaybackEngine@204f80d6

                So same thing, just a different format. I'm going to keep trying different wav files, but is there a specific list of formats it can handle so I can try to see if those work?

                And I'll worry about the mp3s after I figure out the wav files.
                • 5. Re: Failed to realize exception
                  captfoss
                  852766 wrote:
                  is there a specific list of formats it can handle so I can try to see if those work?
                  Yes.

                  http://www.oracle.com/technetwork/java/javase/formats-138492.html

                  And the file you just tried is on it...

                  Sounds like maybe JMF isn't installed correctly.
                  • 6. Re: Failed to realize exception
                    855769
                    I reinstalled it and I still get the error. I'm on Windows 7 and I'm using Netbeans 7.0 and I added the library path to the project. Did I miss anything?
                    • 7. Re: Failed to realize exception
                      captfoss
                      852766 wrote:
                      Did I miss anything?
                      Not that I'm aware of, but there are some special instructions you should follow for a Windows 7 install...

                      Install JMF on Windows 7 64bit