1 Replies - 3810 Views - Last Post: 22 March 2011 - 07:17 AM Rate Topic: -----

#1 cyberbemon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 14-October 10

Java media player not working !

Posted 21 March 2011 - 05:30 AM

hello guys i came across a tutorial that shows you how to make a Java media player.The problem is when i open a File (according to the tutorial the program should be able to play .avi,.swf,.spl,.mp3,.mpeg, .mpg,.mov) i get the following error.The code was provided in the tutorial and i have included it here !

opening MP3 file

Quote

Unable to handle format: mpeglayer3, 44100.0 Hz, 16-bit, Stereo, LittleEndian, Signed, 24000.0 frame rate, FrameSize=32768 bits
Failed to realize: com.sun.media.PlaybackEngine@10ed32c4
Error: Unable to realize com.sun.media.PlaybackEngine@10ed32c4
Could not realize media playe
r


opening .mpg

Quote

Unable to handle format: MPEG, 352x240, FrameRate=29.9, Length=126720
Unable to handle format: mpegaudio, 44100.0 Hz, 16-bit, Stereo, LittleEndian, Signed, 28000.0 frame rate, FrameSize=32768 bits


// Fig 21.6: MediaPanel.java
// A JPanel the plays media from a URL
import java.awt.BorderLayout;
import java.awt.Component;
import java.io.IOException;
import java.net.URL;
import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.swing.JPanel;

public class MediaPanel extends JPanel
{
   public MediaPanel( URL mediaURL )
   {
      setLayout( new BorderLayout() ); // use a BorderLayout
      
      // Use lightweight components for Swing compatibility
      Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );
      
      try
      {
         // create a player to play the media specified in the URL
         Player mediaPlayer = Manager.createRealizedPlayer( mediaURL );
         
         // get the components for the video and the playback controls
         Component video = mediaPlayer.getVisualComponent();
         Component controls = mediaPlayer.getControlPanelComponent();
         
         if ( video != null ) 
            add( video, BorderLayout.CENTER ); // add video component

         if ( controls != null ) 
            add( controls, BorderLayout.SOUTH ); // add controls
         
         mediaPlayer.start(); // start playing the media clip
      } // end try
      catch ( NoPlayerException noPlayerException )
      {
         System.err.println( "No media player found" );
      } // end catch
      catch ( CannotRealizeException cannotRealizeException )
      {
         System.err.println( "Could not realize media player" );
      } // end catch
      catch ( IOException iOException )
      {
         System.err.println( "Error reading from the source" );
      } // end catch
   } // end MediaPanel constructor
} // end class MediaPanel



TEST

// Fig. 21.7: MediaTest.java
// A simple media player
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

public class MediaTest
{
   // launch the application
   public static void main( String args[] )
   {
      // create a file chooser
      JFileChooser fileChooser = new JFileChooser();
      
      // show open file dialog
      int result = fileChooser.showOpenDialog( null );

      if ( result == JFileChooser.APPROVE_OPTION ) // user chose a file
      {
         URL mediaURL = null;
         
         try
         {
            // get the file as URL
            mediaURL = fileChooser.getSelectedFile().toURL();
         } // end try
         catch ( MalformedURLException malformedURLException )
         {
            System.err.println( "Could not create URL for the file" );
         } // end catch

         if ( mediaURL != null ) // only display if there is a valid URL
         {
            JFrame mediaTest = new JFrame( "Media Tester" );
            mediaTest.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            
            MediaPanel mediaPanel = new MediaPanel( mediaURL );
            mediaTest.add( mediaPanel );
            
            mediaTest.setSize( 300, 300 );
            mediaTest.setVisible( true );
         } // end inner if
      } // end outer if
   } // end main
} // end class MediaTest


Is This A Good Question/Topic? 0
  • +

Replies To: Java media player not working !

#2 cyberbemon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 14-October 10

Re: Java media player not working !

Posted 22 March 2011 - 07:17 AM

no one ? o_O
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1