cs_nma
Messages postés
3
Date d'inscription
mardi 3 juin 2003
Statut
Membre
Dernière intervention
12 octobre 2005
12 oct. 2005 à 16:33
Salut
J'espere que ce bout de code t'aidera !!
Nico
package video;
import java.awt.*;
import java.util.*;
import javax.media.*;
import javax.media.format.*;
import javax.media.protocol.*;
/**
*
* @author Java
*/
public class FenPrincipale extends javax.swing.JFrame implements ControllerListener {
/** Creates new form FenPrincipale */
public FenPrincipale() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents()
{
bt_captureDevice = new java.awt.Button();
panel1 = new java.awt.Panel();
l_piloteAudio = new java.awt.Label();
l_piloteVideo = new java.awt.Label();
bt_capture = new java.awt.Button();
bt_captureDevice1 = new java.awt.Button();
p_video = new java.awt.Panel();
getContentPane().setLayout(null);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
bt_captureDevice.setLabel("Capture device");
bt_captureDevice.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bt_captureDeviceActionPerformed(evt);
}
});
getContentPane().add(bt_captureDevice);
bt_captureDevice.setBounds(10, 10, 110, 24);
panel1.setLayout(null);
panel1.setBackground(new java.awt.Color(255, 255, 255));
l_piloteAudio.setFont(new java.awt.Font("Dialog", 0, 10));
panel1.add(l_piloteAudio);
l_piloteAudio.setBounds(10, 0, 350, 18);
l_piloteVideo.setFont(new java.awt.Font("Dialog", 0, 10));
panel1.add(l_piloteVideo);
l_piloteVideo.setBounds(10, 20, 350, 20);
getContentPane().add(panel1);
panel1.setBounds(15, 40, 370, 40);
bt_capture.setLabel("Capture");
bt_capture.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bt_captureActionPerformed(evt);
}
});
getContentPane().add(bt_capture);
bt_capture.setBounds(140, 10, 120, 24);
bt_captureDevice1.setLabel("Enregistrer");
getContentPane().add(bt_captureDevice1);
bt_captureDevice1.setBounds(280, 10, 110, 24);
p_video.setLayout(new java.awt.BorderLayout());
getContentPane().add(p_video);
p_video.setBounds(10, 100, 390, 300);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-415)/2, (screenSize.height-441)/2, 415, 441);
}
private void
bt_captureActionPerformed(java.awt.event.ActionEvent evt)
{
// TODO add your handling code here:
try {
DataSource[] ds = new DataSource[2];
ds[0] = Manager.createDataSource(audioCdi.getLocator());
ds[1] = Manager.createDataSource(videoCdi.getLocator());
DataSource dsp = Manager.createMergingDataSource(ds);
dualPlayer = Manager.createPlayer(dsp);
dualPlayer.addControllerListener(this);
dualPlayer.start();
}
catch (Exception e) {}
}
private void
bt_captureDeviceActionPerformed(java.awt.event.ActionEvent evt)
{
// TODO add your handling code here:
CaptureDeviceDialog cdDialog = new CaptureDeviceDialog(this,true);
cdDialog.show();
audioCdi = cdDialog.piloteAudioSelectionne();
videoCdi = cdDialog.piloteVideoSelectionne();
l_piloteAudio.setText("");
l_piloteVideo.setText("");
l_piloteAudio.setText(audioCdi.getName());
l_piloteVideo.setText(videoCdi.getName());
}
public synchronized void controllerUpdate(ControllerEvent event) {
if (event instanceof StartEvent) {
compVisual = dualPlayer.getVisualComponent();
compControl = dualPlayer.getControlPanelComponent();
p_video.add(BorderLayout.CENTER, compVisual);
p_video.add(BorderLayout.SOUTH, compControl);
validate();
}
}
// Variables declaration - do not
modify
private java.awt.Button bt_capture;
private java.awt.Button bt_captureDevice;
private java.awt.Button bt_captureDevice1;
private java.awt.Label l_piloteAudio;
private java.awt.Label l_piloteVideo;
private java.awt.Panel p_video;
private java.awt.Panel panel1;
// End of variables
declaration
CaptureDeviceInfo audioCdi;
CaptureDeviceInfo videoCdi;
Player dualPlayer;
Component compVisual;
Component compControl;
}
/*
* CaptureDeviceDialog.java
*
* Created on 14 juin 2005, 15:09
*/
package video;
import java.util.*;
import javax.media.*;
import javax.media.format.*;
/**
*
* @author Java
*/
public class CaptureDeviceDialog extends javax.swing.JDialog {
/** Creates new form CaptureDeviceDialog */
public CaptureDeviceDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
ch_pilotesAudio.removeAll();
ch_pilotesVideo.removeAll();
Vector pilotes = CaptureDeviceManager.getDeviceList(null);
int nbPilotes = pilotes.size();
pilotesAudio = new Vector();
pilotesVideo = new Vector();
for(int i = 0;i<nbPilotes;i++) {
cdi
= (CaptureDeviceInfo)
pilotes.elementAt(i);
formats = cdi.getFormats();
for(int j = 0;j<formats.length;j++) {
if(formats[j] instanceof AudioFormat ) {
pilotesAudio.addElement(cdi);
break;
}
else if(formats[j] instanceof VideoFormat ) {
pilotesVideo.addElement(cdi);
break;
}
}
}
// Remplit les listes deroulantes
for(int i=0;i