LECTEUR VIDEO UTILISANT L'API JMF

thierrytitix Messages postés 9 Date d'inscription dimanche 21 décembre 2003 Statut Membre Dernière intervention 27 février 2005 - 14 juil. 2004 à 16:13
Recay2 Messages postés 26 Date d'inscription vendredi 7 janvier 2011 Statut Membre Dernière intervention 29 juin 2012 - 21 mai 2012 à 17:47
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/24523-lecteur-video-utilisant-l-api-jmf

Recay2 Messages postés 26 Date d'inscription vendredi 7 janvier 2011 Statut Membre Dernière intervention 29 juin 2012
21 mai 2012 à 17:47
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
cs_hakimus Messages postés 25 Date d'inscription samedi 14 octobre 2006 Statut Membre Dernière intervention 8 juillet 2010
10 sept. 2008 à 13:50
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.
jalelouss Messages postés 4 Date d'inscription vendredi 17 novembre 2006 Statut Membre Dernière intervention 8 novembre 2007
8 nov. 2007 à 00:49
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 )
jalelouss Messages postés 4 Date d'inscription vendredi 17 novembre 2006 Statut Membre Dernière intervention 8 novembre 2007
10 oct. 2007 à 02:30
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
decarvk Messages postés 1 Date d'inscription jeudi 7 juin 2007 Statut Membre Dernière intervention 7 juin 2007
7 juin 2007 à 22:40
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)
aladin_1983 Messages postés 10 Date d'inscription samedi 26 février 2005 Statut Membre Dernière intervention 11 mai 2005
11 mai 2005 à 02:43
bonjour

bon mon probleme c ke le programme ca se compile avec succes avec la commande: javac video_Player.java

mais est ce ke tu peux donner la ligne de commande pour l execution .

et merci.
sboukr Messages postés 1 Date d'inscription samedi 9 octobre 2004 Statut Membre Dernière intervention 10 mai 2005
10 mai 2005 à 17:32
ajouter ces exception a votre player....si ta cette erreur
java.io.IOException: File Not Found
java.io.IOException: File Not Found
Error creating player
et bon courage
public void init()
{
MediaLocator medialocator = null;
Object obj = null;
if ((s getParameter("FILE")) null)
System.out.println("S value is:NULL");
Fatal("Invalid media file parameter");
try
{
URL url = new URL(getDocumentBase(), s);
System.out.println("URL Value is:" + url);
s = url.toExternalForm();
}
catch(MalformedURLException malformedurlexception) { }
try
{
if((medialocator new MediaLocator("file:" + s)) null)
Fatal("Can't build URL for " + s);
System.out.println("catch in malformed");
try
{
player = Manager.createPlayer(medialocator);
System.out.println("it is from create player");
}
catch(NoPlayerException noplayerexception)
{
System.out.println(noplayerexception);
Fatal("Could not create player for " + medialocator);
}
}
catch(MalformedURLException malformedurlexception1)
{
Fatal("Invalid media file URL!");
}
catch(IOException ioexception)
{
Fatal("IO exception creating player for " + medialocator);
}
}

public void start()
{
if(player != null)
player.start();
System.out.println("This from start");
}

public void stop()
{

if(player != null)
{
System.out.println("This from stop");
player.stop();
player.deallocate();
}
}

public void destroy()
{
player.close();
System.out.println("This from Destory");
}

void Fatal(String s)
{
System.err.println("FATAL ERROR: " + s);
throw new Error(s);
}

Player player;
}
cRaZy_mEhDi Messages postés 1 Date d'inscription jeudi 5 mai 2005 Statut Membre Dernière intervention 7 mai 2005
7 mai 2005 à 02:33
HAHAHA, waaaa les polytechniciens rakom mhansriiiine, hahaha
aladin_1983 Messages postés 10 Date d'inscription samedi 26 février 2005 Statut Membre Dernière intervention 11 mai 2005
26 avril 2005 à 22:59
Bonjour,

votre lecteur se compile avec succes mais lors de l 'execution avec la commande "java MediaPlayer" sur msdos il me donne l erreur suivante:

java.io.IOException:File not found
java.io.IOException:File not found
Error creating file

Si vous avez la solution n'hesiter pas a me la passer et merci d'avance.
cs_AbriBus Messages postés 492 Date d'inscription jeudi 28 août 2003 Statut Membre Dernière intervention 25 avril 2007 5
12 avril 2005 à 04:17
Salut...
Lol,, je croyais que c'était Relire deux fois s'il le fallait... les posts en double c'est pour au cas ou vous en perdriez un ? :D
Lire 4 vilms a la fois...? hmmmm... il me manque au moins deux yeux a moi pour ca lol...
;)
Bon courrage...
AbriBus
khalid 2005 Messages postés 2 Date d'inscription jeudi 7 avril 2005 Statut Membre Dernière intervention 8 avril 2005
8 avril 2005 à 12:58
salut,ton programme m'a aidé bcp,mais j'ai tjrs un probleme de l'execution,pouvez vous m'inmformer comment je pourrai faire,et aussi comment je peux lire 4films a la fois,merci d'avance
aladin_1983 Messages postés 10 Date d'inscription samedi 26 février 2005 Statut Membre Dernière intervention 11 mai 2005
4 avril 2005 à 13:00
salut , j ai pas recu de reponse .mais j y suis arriver a le compiler avec succes . mais le probleme c dans l execution .il me dit il faut le url de la video.

si kelkun peut me repondre ca serait gentil et merci.
aladin_1983 Messages postés 10 Date d'inscription samedi 26 février 2005 Statut Membre Dernière intervention 11 mai 2005
28 févr. 2005 à 17:24
resalut ,

le package videoplayer . il me le faut pour compiler. si kelkun l as k il me l envoie ca serait super et merci.
asamba2005 Messages postés 2 Date d'inscription samedi 27 novembre 2004 Statut Membre Dernière intervention 28 février 2005
28 févr. 2005 à 10:16
Salut tt le monde
j ai essayé mé ca marche pa car la vidéo est lue avec Jmstudio mé avec ton programme c tjr le meme probleme meme sous windows. est ce ke je doit telecharger autre chose
merci de m avoir repodu et désolé pr mon retard.
Merci infiniment
aladin_1983 Messages postés 10 Date d'inscription samedi 26 février 2005 Statut Membre Dernière intervention 11 mai 2005
27 févr. 2005 à 22:13
merci ,

mais ou est ce ke je peux trouver un jre .

et aussi si vous avez un code source pour un lecteur Mpeg avec la possibilite de lire 4 films a la fois .

merci encore.
thierrytitix Messages postés 9 Date d'inscription dimanche 21 décembre 2003 Statut Membre Dernière intervention 27 février 2005
27 févr. 2005 à 19:09
Aladin:
Installer un JRE et un JMF voici la page pour le JMF:
http://java.sun.com/products/java-media/jmf/2.1.1/download.html

Asamba:
Pour le codec c etait ca?
aladin_1983 Messages postés 10 Date d'inscription samedi 26 février 2005 Statut Membre Dernière intervention 11 mai 2005
26 févr. 2005 à 20:44
re

je travaille sur windows et j ai la version 1.4.1 de java

j ai oublie de le mentionner

merci d'avance
aladin_1983 Messages postés 10 Date d'inscription samedi 26 février 2005 Statut Membre Dernière intervention 11 mai 2005
26 févr. 2005 à 20:42
bonjour,

j ai fais copiercoller de ton programme thierrytitix, et je veux savoir ce ke je dois faire pour l executer et ce ke je dois installer comme programme.
thierrytitix Messages postés 9 Date d'inscription dimanche 21 décembre 2003 Statut Membre Dernière intervention 27 février 2005
23 févr. 2005 à 21:47
il te manque un codec ou ce code ne marche pas. Essaye avec une autre video compressée avec un autre codec.
asamba2005 Messages postés 2 Date d'inscription samedi 27 novembre 2004 Statut Membre Dernière intervention 28 février 2005
22 févr. 2005 à 13:18
Salut Je viens faire mes débuts avec JMF et je teste actuellement votre programme sur Linux SUSE 9.1 et ça donne le Message d'erreur suivant
Unable to handle format: MP42, 320x233, FrameRate=12.0, Length=223680 0 extra bytes
Failed to realize: com.sun.media.PlaybackEngine@120d62b
Error: Unable to realize com.sun.media.PlaybackEngine@120d62b
Svp si vous avez une idée je vous serai reconnaissant et merci
intel4 Messages postés 9 Date d'inscription jeudi 1 avril 2004 Statut Membre Dernière intervention 28 septembre 2004
28 sept. 2004 à 10:45
voilà je propose un autre code, pour la transformation en applet
d'abord je fais un panel, ce qui me permet de l'utiliser facilement avec les applets. Mais le problème que je rencontre c'est que le player ne s'affiche pas. pas d'erreurs de compilation, l'applet s'affiche mais pas avec le player. Si quelqu'un a une solution, j'en serai vraiment ravi.

voici le code



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

/*****************************
* MediaPlayer Class *
*****************************/
public class MediaPlayer extends JPanel 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 segment = 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.
setLayout( new BorderLayout() ); /* Sets the layout manager for this container.
Constructs a new border layout with no gaps between components. */
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("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 ("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();
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);

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 = 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() );
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));
}


}

/*------------MediaPlayerApplet.java----------------------------

import javax.swing.*;
import javax.swing.JApplet;


public class MediaPlayerApplet extends JApplet
{
//MediaPlayerApplet applet;

public void init()
{


JFrame f = new JFrame();
String args=null;
MediaPlayer m= new MediaPlayer(args);
f.getContentPane().add(m);
//applet.pack();
f.setVisible(true);

}
}


/*---------------------test de l'applet -----------------------------------


<html>

<head>
<title>Jouer un fichier video 2</title>
</head>






</html>
intel4 Messages postés 9 Date d'inscription jeudi 1 avril 2004 Statut Membre Dernière intervention 28 septembre 2004
24 sept. 2004 à 13:10
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 JPanel 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 segment = 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("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 ("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();
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(segment);
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("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));
}

}

//------------------- Applet-------------------------

import javax.swing.JApplet;

/*Class Main extends JFrame
{
public Main(String [] args)
{
new MediaPlayer(this, args);
}
}*/

public class MediaPlayerApplet extends JApplet
{

static MediaPlayerApplet applet;


public void init()
{

applet=this;
JFrame f = new JFrame();
String args="asimo.mov";
//Main a=new Main(args);
MediaPlayer m= new MediaPlayer(f,args);
applet.getContentPane().add(m);


}
}
intel4 Messages postés 9 Date d'inscription jeudi 1 avril 2004 Statut Membre Dernière intervention 28 septembre 2004
24 sept. 2004 à 11:14
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 JPanel 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 segment = 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("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 ("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();
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(segment);
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("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));
}

}

//------------------- Applet-------------------------

import javax.swing.JApplet;

/*Class Main extends JFrame
{
public Main(String [] args)
{
new MediaPlayer(this, args);
}
}*/

public class MediaPlayerApplet extends JApplet
{

static MediaPlayerApplet applet;


public void init()
{

applet=this;
JFrame f = new JFrame();
String args="asimo.mov";
//Main a=new Main(args);
MediaPlayer m= new MediaPlayer(f,args);
applet.getContentPane().add(m);


}
}
intel4 Messages postés 9 Date d'inscription jeudi 1 avril 2004 Statut Membre Dernière intervention 28 septembre 2004
24 sept. 2004 à 11:09
ok, je verai aussi cet week end ce que ça va donner avec le passage de paramètres.

Je t'envoie les modifications que j'ai essayé pour la transforamtion en applet. ça ne marche pas pour le moment.
thierrytitix Messages postés 9 Date d'inscription dimanche 21 décembre 2003 Statut Membre Dernière intervention 27 février 2005
22 sept. 2004 à 19:26
Tout d'abord vu que la méthode main peut recevoir des éléments args, il semble possible lors du lancement du jar exécutable de filer des paramètres. En le lançant avec un .bat ou un .sh par exemple.
Fais des sytem.out .println(args[n]) , tu verras les arguments passés en ligne de commande.

Ensuite pour le problème de transformer le code en applet je vais le faire ce week end.Si le code à évolué envoie le moi par mail comme çà tu auras la meilleure mise à jour possible.
intel4 Messages postés 9 Date d'inscription jeudi 1 avril 2004 Statut Membre Dernière intervention 28 septembre 2004
22 sept. 2004 à 16:50
Shamamatt, j'attends toujours
Ou en es tu avec la transformation en applet?
intel4 Messages postés 9 Date d'inscription jeudi 1 avril 2004 Statut Membre Dernière intervention 28 septembre 2004
28 juil. 2004 à 18:33
ok, tout d'abord je vais essayer de transformer le fichier java en applet car c'est pas toujours evident et après je te dirai ou j'en suis. Merci
Shamamatt Messages postés 8 Date d'inscription vendredi 2 juillet 2004 Statut Membre Dernière intervention 22 juillet 2004
22 juil. 2004 à 11:48
J'ai essaye de faire un .jar executable, j'ai reussi mais je suis oblige de mettre l'adresse complete des images et de la video...donc mon .jar executable ne fonctionne que sur mon ordi forcement...Si je laisse
("videoPlayer/video/open.avi" ).setVisible( true );
comme on le trouve dans le main, le fichier de la video n'est pas trouve... j'ai essaye de mettre ./ ou ../ devant "videoPlayer" mais ca marche pas plus... est ce que qq'1 a reussi a resoudre ce probleme ?
thierrytitix Messages postés 9 Date d'inscription dimanche 21 décembre 2003 Statut Membre Dernière intervention 27 février 2005
21 juil. 2004 à 23:08
Oui j ai une solution relativement facile et élégante:enfin je pense ...
tu fais un fichier jar avec le java mais tu transforme le java de maniere a ce que ce soit une applet qui prend comme parametre le nom du fichier et voila le tour est joué je le ferais ptet si j ai le temps et que tu sais pas comment faire sinon bon courage.
Le click permet de recharger la page avec la video insérée sous forme d 'applet paramétrée avec le nom sur lequel tu as cliqué.
intel4 Messages postés 9 Date d'inscription jeudi 1 avril 2004 Statut Membre Dernière intervention 28 septembre 2004
21 juil. 2004 à 14:44
Comment ( "java nomdufichier")? comme appelle d'un module externe? 'avec (exec (java nomdufichier))? mais pour ça, il faudra que la commande java soit reconnu.

en fait moi je suis sous linux et je travail avec le serveur apache. Mon souci est de permettre à partir d'un clik sur un nom de video(sous forme de lien) le document video joue dans le player.

Avez vous une solution pour ça?
thierrytitix Messages postés 9 Date d'inscription dimanche 21 décembre 2003 Statut Membre Dernière intervention 27 février 2005
19 juil. 2004 à 19:30
oui c possible, il suffit de creer à partir de ce fichier un exe et de le lancer par l intermédiaire de php en demarrant un processus qui demarrera le fichier java(on peut meme le lancer en lancant "java nomdufichier" depuis php).
On peut envisager aussi l'autre sens et lancer un fichier en php depuis le java à condition de posseder un serveur php.
Il faudrait que tu detailles ce que tu voudrais faire exactement à partir de ce fichier java.
Shamamatt Messages postés 8 Date d'inscription vendredi 2 juillet 2004 Statut Membre Dernière intervention 22 juillet 2004
19 juil. 2004 à 16:09
je sais pas... dsl

^_^
intel4 Messages postés 9 Date d'inscription jeudi 1 avril 2004 Statut Membre Dernière intervention 28 septembre 2004
19 juil. 2004 à 15:53
très bien mais est il possible de le faire communiquer avec du php?
intel4 Messages postés 9 Date d'inscription jeudi 1 avril 2004 Statut Membre Dernière intervention 28 septembre 2004
19 juil. 2004 à 15:52
très bien mais est il possible de le faire communiquer avec du php?
Shamamatt Messages postés 8 Date d'inscription vendredi 2 juillet 2004 Statut Membre Dernière intervention 22 juillet 2004
14 juil. 2004 à 18:29
OK, ca marche qd meme tres bien ! merci beaucoup !

a+

shamamatt
thierrytitix Messages postés 9 Date d'inscription dimanche 21 décembre 2003 Statut Membre Dernière intervention 27 février 2005
14 juil. 2004 à 18:19
Bon ben voila je te livre le fichier corrigé avec un thread en plus pour bouger la barre ca a l air de marcher mais c de l approximatif , je debute en multithread.
C est aussi de l approximatif pour la barre de scroll qui ne devrait pas etre la representation exacte de la longueur du film mais plutot d'un multiple de cette longueur afin de faire un entier sinon la derniere seconde risque de ne pas etre représentée sur la barre enfin bon tu me diras c pas si grave.
Parfois il arrive des erreurs mais non bloquantes.

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 = true;
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;
private CLSr csr = null;
private Time duration = null;
private MoveTick mt = 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;
}
}
private void validateSlider()
{
Time tm = duration;
System.out.println(duration);
slider.setMaximum((int)duration.getSeconds());
slider.setMinimum(0);

}

/********************************************************
* 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)
{
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();

//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);
System.out.println("validate");
Time tm = player.getDuration();
System.out.println(tm.getSeconds());
slider = new JSlider(JSlider.HORIZONTAL,0,(int)(tm.getSeconds()),0);
csr = new CLSr(slider,player);
slider.addChangeListener(csr);

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)
{
slider.removeChangeListener(csr);
csr=null;
mt=null;
//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 == JFileChooser.APPROVE_OPTION)
{
file = fc.getSelectedFile(); //recover the selected file
String address = file.getPath();//recover the address of the file
loadMovie( address );
player.start();
csr = new CLSr(slider,player);
mt = new MoveTick(player,slider,csr);
mt.start();
slider.addChangeListener(csr);
}
}

});

//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);
validateSlider();
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. */
}
}
}




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


public class CLSr implements javax.swing.event.ChangeListener
{
JSlider slider = null;
Player player = null;
public CLSr(JSlider slider,Player player)
{
this.slider = slider;
this.player = player;
}
public void stateChanged(ChangeEvent e)
{
float tm = slider.getValue();
player.setMediaTime(new Time(tm));
}
}





private class MoveTick extends Thread
{
Player player=null;
JSlider slider = null;
CLSr csr = null;
public MoveTick(Player player,JSlider slider,CLSr csr)
{
this.player = player;
this.slider = slider;
this.csr = csr;
}

public void run() {
while (true) {
try {
slider.removeChangeListener(csr);
slider.setValue((int)(player.getMediaTime().getSeconds()));
slider.addChangeListener(csr);
Thread.sleep(1000);
} catch (InterruptedException e) {
break;
}
}
}
public void reset() {

}
}

}
Shamamatt Messages postés 8 Date d'inscription vendredi 2 juillet 2004 Statut Membre Dernière intervention 22 juillet 2004
14 juil. 2004 à 18:07
ah oui j'avais pas vu ca...c bien !
c sympa de regarder pour le scroll... MERCI
thierrytitix Messages postés 9 Date d'inscription dimanche 21 décembre 2003 Statut Membre Dernière intervention 27 février 2005
14 juil. 2004 à 17:02
oui ok c vrai la scroll n a pas l air de suivre mais neanmoins si tu la selectionne avec la souris ca va direct la ou tu veux dans le film.
Je regarde pour le scroll.
Shamamatt Messages postés 8 Date d'inscription vendredi 2 juillet 2004 Statut Membre Dernière intervention 22 juillet 2004
14 juil. 2004 à 16:27
Merci de me proposer une solution...mais j'ai essaye et le slider n'avance pas...ca marche chez toi ? moi, il y a juste le nombre de traits qui varie celon la video ki est ouverte mais le slider reste a son point de depart qd la video se lance...j'ai pas le temps de me replonger la dedans pour l'instant...
encore merci...
a+

shamamatt
thierrytitix Messages postés 9 Date d'inscription dimanche 21 décembre 2003 Statut Membre Dernière intervention 27 février 2005
14 juil. 2004 à 16:15
ok désolé je voulais tester ce truc j avais jamais essayé . Voici une solution faite un peu à la va vite mais j espere que ca conviendra.
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 = true;
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;
private CLSr csr = null;
private Time duration = 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;
}
}
private void validateSlider()
{
Time tm = duration;
System.out.println("toto"+tm.getSeconds());
slider.setMaximum(1160);
slider.setMinimum(0);
// creates a slider with the specified orientation and the specified minimum, maximum, and initial values

}

/********************************************************
* 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)
{
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();

//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);
System.out.println("validate");
Time tm = player.getDuration();
System.out.println(tm.getSeconds());
slider = new JSlider(JSlider.HORIZONTAL,0,(int)(tm.getSeconds()),0);
csr = new CLSr();
slider.addChangeListener(csr);

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)
{
slider.removeChangeListener(csr);
//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 == JFileChooser.APPROVE_OPTION)
{
file = fc.getSelectedFile(); //recover the selected file
String address = file.getPath();//recover the address of the file
loadMovie( address );
player.start();
validateSlider();
slider.addChangeListener(csr);
}
}

});

//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. */
}
}
}







/************
* Main *
************/
public static void main( String[] args )
{ // needs the address of a movie: *.avi,*.mpg...
new MediaPlayer("videoPlayer/video/open.avi" ).setVisible( true );
}
public class CLSr implements javax.swing.event.ChangeListener
{
public CLSr()
{
}
public void stateChanged(ChangeEvent e)
{
System.out.println("state");
float tm = slider.getValue();
System.out.println("value="+tm);
player.setMediaTime(new Time(tm));
}
} }