title: How to start video quick on a JFrame using JMF
body: <p>Can anyone please tell me which is the best way to play video in a JPanel.I am currently working on a learning software for children where some learning videos will be played upon selection.Videos are stored in some folder.I have successfully done the job using JMF but the problem is its kinda slow.It takes some time to start the video, though the videos are not too large(2-4 MB).What can i do to make it quick-start,</p>
  
  <p>Thank u</p>
  
  <pre><code>public class MediaPanel extends JPanel
  {
  public static boolean playing = false;
  public static Player mediaPlayer;
  public MediaPanel( URL mediaURL )
  {
  setLayout( new BorderLayout() ); // use a BorderLayout
  // Use lightweight components for Swing compatibility
  
  //Component controls = mediaPlayer.getControlPanelComponent();
  } // end MediaPanel constructor
  public void play(URL mediaURL) throws NoPlayerException, CannotRealizeException,               IOException, IncompatibleSourceException{
  Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );
  System.out.println("sdfdsg");
  mediaPlayer = Manager.createRealizedPlayer( mediaURL );
  Component video = mediaPlayer.getVisualComponent();
  if ( video != null )
  add( video);
  mediaPlayer.start();
  playing=true;
  }
  public void stop(){
  mediaPlayer.stop();
  playing = false;
  }
  public void play_one(){
  mediaPlayer.stop();
  mediaPlayer.start();
  }
  }
  public class MediaPanel extends JPanel
  {
  public static boolean playing = false;
  public static Player mediaPlayer;
  public MediaPanel( URL mediaURL )
  {
  setLayout( new BorderLayout() ); 
  
  } // end MediaPanel constructor
  public void play(URL mediaURL) throws NoPlayerException, CannotRealizeException,     IOException, IncompatibleSourceException{
  Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );
  mediaPlayer = Manager.createRealizedPlayer( mediaURL );
  Component video = mediaPlayer.getVisualComponent();
  if ( video != null )
  add( video);
  mediaPlayer.start();
  playing=true;
  }
  public void stop(){
  mediaPlayer.stop();
  playing = false;
  }
  public void play_one(){
  mediaPlayer.stop();
  mediaPlayer.start();
  }
  }
  </code></pre>
  
  <p>and the portion of the source code where i used this class..</p>
  
  <pre><code>try {
  Home.text.setText("wait..");
  if(Home.mediaPanel.playing==true)
  Home.mediaPanel.stop();
  Home.mediaPanel.play(new     URL("file://C://Users//zubair//workspace//learningKit//"+Home.selected_topic+"//"+Home.sele cted_group+"//v"+k+".flv"));
  } catch (Exception e1) {
  // TODO Auto-generated catch block
  e1.printStackTrace();
  }
  </code></pre>