Lecteur video utilisant l'api jmf

Soyez le premier à donner votre avis sur cette source.

Vue 35 976 fois - Téléchargée 6 298 fois

Description

J'ai utilise un code que j'ai trouve sur ce site et je l'ai modifie. J'ai rajoute plusieurs boutons et un slider...et c'est la mon probleme, je n'arrive pas a faire avancer le slider en meme temps que la video..... si qq'1 pouvait voir ca ce serait vraiment sympa...
^_^

Conclusion :


il y a des lignes de codes qui ne servent peut etre pas...

Codes Sources

A voir également

Ajouter un commentaire

Commentaires

Messages postés
27
Date d'inscription
vendredi 7 janvier 2011
Statut
Membre
Dernière intervention
29 juin 2012

Slt tout le monde, ça fait une semaine que je cherche comment régler ce problème mais j'arrive si quelqu'un pourra m'aider je lui serait reconnaissant voila mon problème:
Unable to handle format: MP42, 320x233, FrameRate=12.0, Length=223680 0 extra bytes
Failed to realize: com.sun.media.PlaybackEngine@ad3ba4
Error: Unable to realize com.sun.media.PlaybackEngine@ad3ba4
Messages postés
25
Date d'inscription
samedi 14 octobre 2006
Statut
Membre
Dernière intervention
8 juillet 2010

Bonjour,

je viens de réaliser un player semblable à celui-là, qui fonctionne très bien, mais il me reste un petit problème :
Quand la vidéo tourne, les déplacements du slider son pris en compte. Mais quand elle est en pause, l'affichage ne s'actualise plus! Il faut obligatoirement refaire play pour que la vidéo saute d'un coup, c'est moche.

Comment faire pour que l'affichage de la vidéo se mette à jour même quand elle est en pause??
J'ai déjà essayé repaint() et validate(), tous les deux sans succès...

Merci à tous.
Messages postés
4
Date d'inscription
vendredi 17 novembre 2006
Statut
Membre
Dernière intervention
8 novembre 2007

Salut tout le monde , j'ai une question concernant ce code , par exemple je veux lire la video concerné a un instant t je m'expliques :
par exemple la video debute a t0=0:0:0 et elle se termine a tf=X:Y:Z
par exemple je veux qu'elle se lit a l'instant t1 compris entre t0 et tf
Merci (c urgent aidez moi svp tres vite )
Messages postés
4
Date d'inscription
vendredi 17 novembre 2006
Statut
Membre
Dernière intervention
8 novembre 2007

Bonsoir, j'ai le code :
package videoPlayer;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.media.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;

/*****************************
* MediaPlayer Class *
*****************************/
class MediaPlayer extends JFrame implements ControllerListener
{
private Player player = null;
private JPanel videoPanel = null;
private JSlider slider = null;
private volatile Thread slider_updater = null;
private volatile boolean follows_slider = false;
private JToggleButton start_stop = new JToggleButton();
float step = 1.0f / 10;


private JMenuBar menu_bar = null; // menu bar used for the different Buttons
private JFrame frame = null; // frame used to open a file
private JFileChooser fc = null; // used for the dialog window to open a file
private File file;

/* Various Buttons */
private JButton open = null;
private JButton play = null;
private JButton pause = null;
private JButton stop = null;
private JButton about = null;


/***********************************************
* MediaPlayer Builder *
* needs the address of a movie as an argument *
***********************************************/
public MediaPlayer( String nomFilm )
{
super(); /* Constructs a new frame that is initially invisible.
This constructor sets the component's locale property to the value returned by JComponent.*/
setLocation( 400, 200 ); /* Moves this component to a new location. The top-left corner of the new location is specified by the
x and y parameters in the coordinate space of this component's parent. */
setTitle("Video Player"); // Sets the title for this frame to the specified string.
getContentPane().setLayout( new BorderLayout() ); /* Sets the layout manager for this container.
Constructs a new border layout with no gaps between components. */
addWindowListener( new WindowAdapter() /* Adds the specified window listener to receive window events from this window */
{
public void windowClosing( WindowEvent we ) /* Invoked when a window is in the process of being closed. The close operation can be overridden at
this point.*/
{
JOptionPane.showMessageDialog(null, "Thank you to have used Video Player", "Quit",JOptionPane.INFORMATION_MESSAGE);
/* Brings up a dialog that displays a message using a default icon determined by the messageType
parameter. */
System.exit(0); // Terminates the currently running Java Virtual Machine.
}
}
);

if ( nomFilm != null)
loadMovie( nomFilm ); // load the movie
}

/******************************************
* method of loading of film from its URL *
******************************************/
private void loadMovie( String movieURL )
{
if ( movieURL.indexOf( ":" ) < 3 ) movieURL = "file:" + movieURL;
try
{ // creation of the player

player = Manager.createPlayer( new MediaLocator( movieURL ) );
player.addControllerListener( this ) ;
player.realize();
}
catch (Exception e)
{
System.out.println("Error creating player");
return;
}
}

/********************************************************
* intercept all the events in provenence of the player *
********************************************************/
public void controllerUpdate( ControllerEvent ce )
{
// to change the icon of tje player
Toolkit tk = Toolkit.getDefaultToolkit();
setIconImage(new ImageIcon("videoPlayer/icons/icon.gif").getImage());

// to give the duration of the movie
if (ce instanceof DurationUpdateEvent)
{
Time duration= ((DurationUpdateEvent) ce).getDuration();
System.out.println( "duration: " + (int)duration.getSeconds()+" seconds");
}

// to start the video and create all the buttons etc...
if ( ce 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 ("videoPlayer/icons/open.gif"));
open.setMargin(new Insets( 0, 0, 0, 0));
play = new JButton(new ImageIcon ("videoPlayer/icons/play.gif"));
play.setMargin(new Insets( 0, 0, 0, 0));
pause = new JButton(new ImageIcon ("videoPlayer/icons/pause.gif"));
pause.setMargin(new Insets( 0, 0, 0, 0));
stop = new JButton(new ImageIcon ("videoPlayer/icons/stop.gif"));
stop.setMargin(new Insets( 0, 0, 0, 0));
about = new JButton(new ImageIcon ("videoPlayer/icons/about.gif"));
about.setMargin(new Insets( 0, 0, 0, 0));

//creation of the frame used to open a file
frame = new JFrame();
fc = 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);

//the buttons are add to the menu bar
menu_bar.add(open);
menu_bar.add(play);
menu_bar.add(pause);
menu_bar.add(stop);
menu_bar.add(about);


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

//to set the menu bar
setJMenuBar(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("videoPlayer/icons/icon.gif").getImage());

System.out.println("Open a file");

//posting of a window "of opening"
int choix = fc.showOpenDialog(frame);

if(choix == fc.APPROVE_OPTION)
{
file = fc.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() );
getContentPane().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 ( ce 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. */
}
}
}


void slider_stateChanged(ActionEvent e)
{
if (follows_slider)
{
float tm = slider.getValue() * step;
player.setMediaTime(new Time(tm));
}
}

private void validateSlider()
{
Time tm = player.getMediaTime();
slider.setValue((int)(tm.getSeconds() / step));
}

/************
* Main *
************/
public static void main( String[] args )
{ // needs the address of a movie: *.avi,*.mpg...
new MediaPlayer("videoPlayer/video/open.avi" ).setVisible( true );
}

}

et j'ai trouvé des erreurs apres l'exécution de ce player :
Unable to handle format: MP42, 320x233, FrameRate=12.0, Length=223680 0 extra bytes
Failed to realize: com.sun.media.PlaybackEngine@194ca6c
Error: Unable to realize com.sun.media.PlaybackEngine@194ca6c

SVP ,aidez moi a corriger cette erreur sachant que j'ai changé la video de test mais pariel y a des erreurs genre IOException
Messages postés
1
Date d'inscription
jeudi 7 juin 2007
Statut
Membre
Dernière intervention
7 juin 2007

bonjour j'ai un problem aidez moi svp

message d'erreur(de la console java)
ava.lang.NoClassDefFoundError: MediaPlayer (wrong name: videoPlayer/MediaPlayer)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Afficher les 40 commentaires

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.