salut tous
j'ai besoin de votre aide à propos de la façon ou (API) pour lire des fichier audios et vidéos avec java
merci
Version imprimable
salut tous
j'ai besoin de votre aide à propos de la façon ou (API) pour lire des fichier audios et vidéos avec java
merci
:salut:
c'est la bibliothèque JMF (java media framework)qui te permet de lire les fichier multimedia===> video et audio ;)
.si t'as besoin de lire un avi tu peu utiliser ce code.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181 /* * MediaPlayerDemo.java * * Created on 25 avril 2008, 15:26 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package test; /** * * @author ADEL */ /* * @(#)MediaPlayerDemo.java 1.5 01/03/13 * * Copyright (c) 1999-2001 Sun Microsystems, Inc. All Rights Reserved. * * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use, * modify and redistribute this software in source and binary code form, * provided that i) this copyright notice and license appear on all copies of * the software; and ii) Licensee does not utilize the software in a manner * which is disparaging to Sun. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * This software is not designed or intended for use in on-line control of * aircraft, air traffic, aircraft navigation or aircraft communications; or in * the design, construction, operation or tenance of any nuclear * facility. Licensee represents and warrants that it will not use or * redistribute the Software for such purposes. */ // Lire des fichiers multimédia avec le Java Media Player. import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; import javax.media.*; import javax.media.Control; public class MediaPlayerDemo extends JFrame { private Player lecteur; private File fichier; public MediaPlayerDemo() { super( "Démonstration du Java Media Player" ); JButton ouvrirFichier = new JButton( "Ouvrir le fichier à lire" ); ouvrirFichier.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { ouvrirFichier(); creerLecteur(); } } ); getContentPane().add( ouvrirFichier, BorderLayout.NORTH ); setSize( 500, 300 ); show(); } public void ouvrirFichier() { JFileChooser choixDeFichier = new JFileChooser(); choixDeFichier.setFileSelectionMode( JFileChooser.FILES_ONLY ); int resultat = choixDeFichier.showOpenDialog( this ); // Utilisateur clique sur le bouton Annuler dans le dialogue. if ( resultat == JFileChooser.CANCEL_OPTION ) fichier = null; else fichier = choixDeFichier.getSelectedFile(); } public void creerLecteur() { if ( fichier == null ) return; retirerLecteurPrecedent(); try { // Creer un nouveau lecteur et ajouter un écouteur. lecteur = Manager.createPlayer( fichier.toURL() ); lecteur.addControllerListener( new GestionnaireEvenement() ); lecteur.start(); // Démarrage du lecteur } catch ( Exception e ){ JOptionPane.showMessageDialog( this, "Fichier ou emplacement invalide", "Chargement du fichier"+ " erroné",JOptionPane.ERROR_MESSAGE ); } } public void retirerLecteurPrecedent() { if ( lecteur == null ) return; lecteur.close(); Component visuel = lecteur.getVisualComponent(); Component controle = lecteur.getControlPanelComponent(); Container c = getContentPane(); if ( visuel != null ) c.remove( visuel ); if ( controle != null ) c.remove( controle ); } public static void main(String args[]) { MediaPlayerDemo application = new MediaPlayerDemo(); application.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit(0); } } ); //application.lecteur.getControl(FramePositioningControl); } // Classe interne pour gérer les événements du lecteur multimédia. private class GestionnaireEvenement implements ControllerListener { public void controllerUpdate( ControllerEvent e ) { if ( e instanceof RealizeCompleteEvent ) { Container c = getContentPane(); // Charger les composants visuel et contrôles sils existent. Component composantVisuel = lecteur.getVisualComponent(); //skip(50); if ( composantVisuel != null ) c.add( composantVisuel, BorderLayout.CENTER ); Component composantControles = lecteur.getControlPanelComponent(); if ( composantControles != null ) c.add( composantControles, BorderLayout.SOUTH ); c.doLayout(); } } } }
Il existe également la librairie QTJava qui peut lire plus de formats.
merci a vous tous :D