title: playing video using jmf
body: <p>I am trying to play a video file using <code>JMF</code> but it gives me <code>No Media Player found exception</code>.</p>
  
  <p>Here is my code, can anyone tell me what I am doing wrong here?</p>
  
  <pre><code>public class MediaPanel extends JPanel {
  public MediaPanel(URL mediaURL) {
      setLayout(new BorderLayout());
  
      try {
          Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
          Player mediaPlayer = Manager.createRealizedPlayer(mediaURL);
          Component video = mediaPlayer.getVisualComponent();
          Component controls = mediaPlayer.getControlPanelComponent();
  
          if (video != null)
  
              add(video, BorderLayout.CENTER);
  
          if (controls != null)
              add(controls, BorderLayout.SOUTH);
  
          mediaPlayer.start();
      } 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");
      }
  }
  }
  
  
  
  public class MediaTest {
  
  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;
          Player mediaPlayer = null;
  
          try {
              // get the file as URL 
              mediaURL = fileChooser.getSelectedFile().toURL();
          } catch (MalformedURLException malformedURLException) {
              System.err.println("Could not create URL for the file");
          }
  
          if (mediaURL != null) {
              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);
          }
      }
  }
  }
  </code></pre>
  
  <p>The exception that I am getting is <code>No media player found</code></p>