intercept all the events in provenence of the player *
********************************************************/
public void controllerUpdate( ControllerEvent controllerEvent )
{
// to change the icon of tje player
Toolkit tk = Toolkit.getDefaultToolkit();
//setIconImage(new ImageIcon(“icons/icon.gif”).getImage());
// to give the duration of the movie
if (controllerEvent instanceof DurationUpdateEvent)
{
Time duration= ((DurationUpdateEvent) controllerEvent).getDuration();
System.out.println( “duration: " + (int)duration.getSeconds()+” seconds");
}
// to start the video and create all the buttons etc…
if ( controllerEvent instanceof RealizeCompleteEvent )
{
if (menu_bar == null)
{
//creation of the menu bar
menu_bar = new JMenuBar();
//creation of the different buttons with the icons
open = new JButton(new ImageIcon (“icons/open.gif”));
open.setMargin(new Insets( 0, 0, 0, 0));
play = new JButton(new ImageIcon (“icons/play.gif”));
play.setMargin(new Insets( 0, 0, 0, 0));
pause = new JButton(new ImageIcon (“icons/pause.gif”));
pause.setMargin(new Insets( 0, 0, 0, 0));
stop = new JButton(new ImageIcon (“icons/stop.gif”));
stop.setMargin(new Insets( 0, 0, 0, 0));
segment = new JButton(new ImageIcon (“icons/segment.gif”));
segment.setMargin(new Insets( 0, 0, 0, 0));
about = new JButton(new ImageIcon (“icons/about.gif”));
about.setMargin(new Insets( 0, 0, 0, 0));
//creation of the frame used to open a file
frame = new JFrame();
fileChooser = new JFileChooser();
//creates a slider with the specified orientation and the specified minimum, maximum, and initial values
slider = new JSlider(JSlider.HORIZONTAL,0,50,0);
JPanel menu = new JPanel();
menu.add(open);
menu.add(play);
menu.add(pause);
menu.add(stop);
menu.add(segment);
menu.add(about);
add(menu, BorderLayout.NORTH);
slider.setMajorTickSpacing(10); //This method sets the major tick spacing
slider.setMinorTickSpacing(2); //This method sets the minor tick spacing
slider.setPaintTicks(true); //Determines whether tick marks are painted on the slider
slider.setPaintLabels(false); //Determines whether labels are painted on the slider
slider.setBorder(BorderFactory.createEmptyBorder(0,0,10,0)); //Sets the border of this component
menu_bar.add(slider); //Appends the slider to the end of the menu bar
//actions which are made while pressing the open button
open.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//modification of the icon
Toolkit tk = Toolkit.getDefaultToolkit();
frame.setIconImage(new ImageIcon("icons/icon.gif").getImage());
System.out.println("Open a file");
//posting of a window "of opening"
int choix = fileChooser.showOpenDialog(frame);
if(choix == fileChooser.APPROVE_OPTION)
{
file = fileChooser.getSelectedFile(); //recover the selected file
String address = file.getPath();//recover the address of the file
loadMovie( address );
player.start();
}
}
});
//actions which are made while pressing the play button
play.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
player.start();
//player.setMediaTime(new Time(0.0));
while(play.isSelected())
{
Time tm = player.getMediaTime();
double t = tm.getSeconds();
if (t > 0.0)
{
player.setMediaTime(new Time(t - step));
}
}
System.out.println("Playing movie");
}
});
//actions which are made while pressing the pause button
pause.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
player.stop();
player.deallocate();
System.out.println("Pause");
}
});
//actions which are made while pressing the stop button
stop.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
player.stop();
player.deallocate();
System.out.println("Stop");
player.setMediaTime(new Time(0)); //puts the video at the beginning
if (player.getTargetState() < Player.Started)
player.prefetch();
}
});
//actions which are made while pressing the about button
about.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("About");
//Brings up a dialog that displays a message using a default icon determined by the messageType parameter
JOptionPane.showMessageDialog(null," Video Player 1.1\n Video Player Java using JMF\n\n version 1.1", "About Video Player",JOptionPane.INFORMATION_MESSAGE);
}
});
}
if ( videoPanel == null)
{ //creation of the panel of sight
videoPanel = new JPanel();
videoPanel.setLayout( new BorderLayout() );
add( videoPanel, BorderLayout.CENTER);
}
else
videoPanel.removeAll();
//obtaining the component restoring the image in provenence of the player.
Component vis = player.getVisualComponent();
if ( vis != null )
{ // if it is valid then we put it in our sight
videoPanel.add( vis, BorderLayout.CENTER);
videoPanel.setVisible(true);
//this.pack(); // resize the size according to the size of film
}
}
else if ( controllerEvent instanceof EndOfMediaEvent )
{
if (player != null)
{ //stop the movie
player.stop();
player.deallocate(); /* Deallocating the Player releases any resources that would prevent another
Player from being started. For example, if the Player uses a hardware device
to present its media, deallocate frees that device so that other Players
can use it. */
}
}
}