Search code examples
javavideojmf

How to play a shot in a video using JMF?


Here's my problem, I'm using the following java code using JMF for playing video. If I want to play a particular part of a video, lets say a shot (with known starting time and ending time), how to do that(if u know the code please post it here as a "method") Thanks in advance.

import java.awt.BorderLayout;
import java.awt.Component;
import java.io.IOException;
import java.net.URL;
import javax.media.*;
import javax.swing.*;
import javax.media.control.FramePositioningControl;

public class MediaPanel extends JPanel
{
public MediaPanel( URL mediaURL )
{
FramePositioningControl fpc;   

setLayout( new BorderLayout() ); =
Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );

try
  {
     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" );
  } 
  catch ( CannotRealizeException cannotRealizeException )
  {
     System.err.println( "Could not realize media player" );
  } 
  catch ( IOException iOException )
  {
     System.err.println( "Error reading from the source" );
  } 


} 
} 

Solution

  • Have a look at JMF player APIs setMediaTime() and setStopTime()