Skip to content

Membuat Aplikasi Video Conference dengan JMF bagian 3: Capture

March 31, 2008

Di post sebelum ini kita sudah membahas bagaimana memainkan multimedia dari local disk. Sekarang kita akan membahas bagaimana caranya untuk capture video dan audio dari web cam dan microphone dan menampilkannya di aplikasi kita.

Pertama, kita buat class untuk menangani format dari video dan audio kita.

import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import javax.media.*;
import javax.media.format.*;
import javax.media.protocol.DataSource;
import javax.swing.*;

public class CaptureDeviceDialog extends Dialog implements ActionListener, ItemListener {

boolean configurationChanged = false;
Vector devices;
Vector audioDevices;
Vector videoDevices;
Vector audioFormats;
Vector videoFormats;
Choice audioDeviceCombo;
Choice videoDeviceCombo;
Choice audioFormatCombo;
Choice videoFormatCombo;

public CaptureDeviceDialog(Frame parent, String title, boolean mode) {
super(parent, title, mode);
init();
}

private void init() {
setSize(450, 180);
Panel p = new Panel();
p.setLayout(null);

Label l1 = new Label(“Audio Device(s)”);
Label l2 = new Label(“Video Device(s)”);
Label l3 = new Label(“Audio Format(s)”);
Label l4 = new Label(“Video Format(s)”);
audioDeviceCombo = new Choice();
videoDeviceCombo = new Choice();
audioFormatCombo = new Choice();
videoFormatCombo = new Choice();

Button OKbutton = new Button(“OK”);
Button cancelButton = new Button(“Cancel”);

p.add(l1);
l1.setBounds(5, 5, 100, 20);
p.add(audioDeviceCombo);
audioDeviceCombo.setBounds(115, 5, 300, 20);
p.add(l3);
l3.setBounds(5, 30, 100,20);
p.add(audioFormatCombo);
audioFormatCombo.setBounds(115, 30, 300,20);
p.add(l2);
l2.setBounds(5, 55, 100, 20);
p.add(videoDeviceCombo);
videoDeviceCombo.setBounds(115, 55, 300, 20);
p.add(l4);
l4.setBounds(5, 80, 100, 20);
p.add(videoFormatCombo);
videoFormatCombo.setBounds(115, 80, 300, 20);
p.add(OKbutton);
OKbutton.setBounds(280, 115, 60, 25);
p.add(cancelButton);
cancelButton.setBounds(355, 115, 60, 25);

add(p, “Center”);
audioDeviceCombo.addItemListener(this);
videoDeviceCombo.addItemListener(this);
OKbutton.addActionListener(this);
cancelButton.addActionListener(this);

//get all the capture devices
devices = CaptureDeviceManager.getDeviceList ( null );
CaptureDeviceInfo cdi;
if (devices!=null && devices.size()>0) {
int deviceCount = devices.size();
audioDevices = new Vector();
videoDevices = new Vector();

Format[] formats;
for ( int i = 0;  i < deviceCount;  i++ ) {
cdi = (CaptureDeviceInfo) devices.elementAt ( i );
formats = cdi.getFormats();
for ( int j=0;  j<formats.length; j++ ) {
if ( formats[j] instanceof AudioFormat ) {
audioDevices.addElement(cdi);
break;
}
else if (formats[j] instanceof VideoFormat ) {
videoDevices.addElement(cdi);
break;
}
}
}

//populate the choices for audio
for (int i=0; i<audioDevices.size(); i++) {
cdi  = (CaptureDeviceInfo) audioDevices.elementAt(i);
audioDeviceCombo.addItem(cdi.getName());
}

//populate the choices for video
for (int i=0; i<videoDevices.size(); i++) {
cdi  = (CaptureDeviceInfo) videoDevices.elementAt(i);
videoDeviceCombo.addItem(cdi.getName());
}

displayAudioFormats();
displayVideoFormats();

} // end if devices!=null && devices.size>0
else {
//no devices found or something bad happened.
}
}

void displayAudioFormats() {
//get audio formats of the selected audio device and repopulate the audio format combo
CaptureDeviceInfo cdi;
audioFormatCombo.removeAll();

int i = audioDeviceCombo.getSelectedIndex();
//i = -1 –> no selected index

if (i!=-1) {
cdi = (CaptureDeviceInfo) audioDevices.elementAt(i);
if (cdi!=null) {
Format[] formats = cdi.getFormats();
audioFormats = new Vector();
for (int j=0; j<formats.length; j++) {
audioFormatCombo.add(formats[j].toString());
audioFormats.addElement(formats[j]);
}
}
}
}

void displayVideoFormats() {
//get audio formats of the selected audio device and repopulate the audio format combo
CaptureDeviceInfo cdi;
videoFormatCombo.removeAll();

int i = videoDeviceCombo.getSelectedIndex();
//i = -1 –> no selected index

if (i!=-1) {
cdi = (CaptureDeviceInfo) videoDevices.elementAt(i);
if (cdi!=null) {
Format[] formats = cdi.getFormats();
videoFormats = new Vector();
for (int j=0; j<formats.length; j++) {
videoFormatCombo.add(formats[j].toString());
videoFormats.addElement(formats[j]);
}
}
}
}

public CaptureDeviceInfo getAudioDevice() {
CaptureDeviceInfo cdi = null;
if (audioDeviceCombo!=null) {
int i = audioDeviceCombo.getSelectedIndex();
cdi = (CaptureDeviceInfo) audioDevices.elementAt(i);
}
return cdi;
}

public CaptureDeviceInfo getVideoDevice() {
CaptureDeviceInfo cdi = null;
if (videoDeviceCombo!=null) {
int i = videoDeviceCombo.getSelectedIndex();
cdi = (CaptureDeviceInfo) videoDevices.elementAt(i);
}
return cdi;
}

public Format getAudioFormat() {
Format format = null;
if (audioFormatCombo!=null) {
int i = audioFormatCombo.getSelectedIndex();
format = (Format) audioFormats.elementAt(i);
}
return format;
}

public Format getVideoFormat() {
Format format = null;
if (videoFormatCombo!=null) {
int i = videoFormatCombo.getSelectedIndex();
format = (Format) videoFormats.elementAt(i);
}
return format;
}

public boolean hasConfigurationChanged() {
return configurationChanged;
}

public void actionPerformed(ActionEvent ae) {
String command = ae.getActionCommand().toString();
if (command.equals(“OK”)) {
configurationChanged = true;
}
dispose();
}

public void itemStateChanged(ItemEvent ie) {
System.out.println(ie.getSource().toString());
if (ie.getSource().equals(audioDeviceCombo))
displayAudioFormats();
else
displayVideoFormats();

}
}
Itu adalah class untuk menangani user yang akan memilih format dari video dan audio yang akan di capture. Selanjutnya, kita tambahkan method capture pada JConference kita.

Pada action File–>Capture, kita ubah

System.out.println(“Sementara”);

menjadi

capture();

Selanjutnya kita tambahkan method capture() dan method-method yang mendukungnya

void registerDevices() {
CaptureDeviceDialog cdDialog = new
CaptureDeviceDialog(this, “Capture Device”, true);
cdDialog.setVisible(true);
if (!cdDialog.hasConfigurationChanged())
return;
//configuration has changed, update variables.
audioCDI = cdDialog.getAudioDevice();
if (audioCDI!=null) {
audioDeviceName = audioCDI.getName();
System.out.println(“Audio Device Name: ” + audioDeviceName);
}
videoCDI = cdDialog.getVideoDevice();
if (videoCDI!=null) {
videoDeviceName = videoCDI.getName();
System.out.println(“Video Device Name: ” + videoDeviceName);
}
//Get formats selected, to be used for creating DataSource
videoFormat = cdDialog.getVideoFormat();
audioFormat = cdDialog.getAudioFormat();
}
public synchronized void controllerUpdate(ControllerEvent event) {
System.out.println(event.toString());
if (event instanceof RealizeCompleteEvent) {
Component comp;
System.out.println(“Adding visual component”);
if ((comp = dualPlayer.getVisualComponent()) != null)
add (“Center”, comp);
System.out.println(“Adding control panel”);
if ((comp = dualPlayer.getControlPanelComponent()) != null)
add(“South”, comp);
validate();
}
}
void capture() {
if (audioCDI==null && videoCDI==null)
registerDevices();

try {
if (!(audioCDI==null && videoCDI==null)) {
DataSource[] dataSources = new DataSource[2];
System.out.println(“Creating data sources.”);
dataSources[0] = Manager.createDataSource(audioCDI.getLocator());
dataSources[1] = Manager.createDataSource(videoCDI.getLocator());
DataSource ds = Manager.createMergingDataSource(dataSources);
dualPlayer = Manager.createPlayer(ds);
dualPlayer.addControllerListener(this);
dualPlayer.start();
}
else
System.out.println(“CDI not found.”);
}
catch (Exception e) {
System.out.println(e.toString());
}
}

Post selanjutnya kita akan membahas tentang transmit receive paket-paket RTP (Real Time Protocol), protokol yang kita pakai untuk aplikasi kita.

EDIT : Saya sudah tidak programming tentang ini lagi dan sudah lupa juga.
Tapi saya masih ada source code yang dulu saya pakai develop dengan netbeans.
Silahkan download di
http://iyeyo.com/JVConfv1.0.rar

From → JConference

33 Comments
  1. mas bisa kirimkan source code lengkap tentang video conference menggunakan jv ke email saya ? saya sedang membuat skripsi tentang video conference ini, trus referensinya dari mana sj y mas? terima kasih sebelumnya
    uchiha_didik@yahoo.com

  2. antony permalink

    ada orang yg senasib ma lu :) )

  3. tukangjava permalink

    @didiksoft
    wah mas didik. saya juga belum selesai. ini juga diposting sambil jalan..

    @antony
    udah lu nonton tokyo hot aja sana gih :P

  4. randi permalink

    mas saya mo mnt jg dong source code , buat tugas multimedia . maksih ya mas sebelumnya !!!! ????

  5. @randi

    mo dikirim kemana mas?

  6. mas,saya butuh bgt source code yang lengkap bsa g….

    makasih bgt ya sebelumnya….

  7. At you the excellent site, a lot of useful info and good design, thank.,

  8. milo permalink

    keren codenya mas…bisa di upload di webnya mas atau di kirim ke mail donk mas…. milocrew@yahoo.com thanks ya mas…

  9. I love you so much! Great place to visit!,

  10. mas, boleh minta source code lengkap juga kah? soalnya nyoba dari yang 1-3 masih banyak errornya. trus bingung declare variablenya dimana, trus tipe datanya apa @-) –> intinya bingung mas :D
    dikirim ke erareac@gmail.com
    makasih banyak ya mas

  11. mas.. makasi tutorialnya…
    kebetulan saya lg belajar java dan ingin membuat aplikasi video conference.
    saya boleh minta source code lengkapnya mas??
    kalo boleh kirim ke andra_72gar@yahoo.com.
    makasih banyak mas

  12. alif permalink

    mas ,
    nice tutor, tp mash mentok neh
    klo boleh minta source code lengkap video conference java
    soalnya mau buat TA bulan ini mulai nya.
    email ku : zee_ruli@yahoo.com
    trimakasih mas

  13. huhauhauua..
    ini anak PU juga???? angkatan brapa bos????
    stress ni gw kodingnya….

  14. Keren Tapi Kalau pakek Netbeans Piye yoh yang matisse itu coz aq mumet modifikasi tutorial ini je yang agak di perjelas sedikit lagi dong mas hehehe… sorry banyak tuntutan

  15. Nih senior kita Ndra angkatan 2004.. Haha..

  16. iocvo permalink

    mas boleh minta source code nya nih
    kebetulan lagi bikin tugas
    tolong kirimin ke agha_iocvo@yahoo.com

  17. anis permalink

    klo boleh minta source code lengkap video conference java jika dengan menggunakan IP camera yang bisa di remote. makasih
    tolong kirimin ke singgih_trijanto@yahoo.com

  18. Agung Syarifudin permalink

    Mas boleh minta source lengkap nya? kebetulan saya sedang mengerjakan tugas yang sama, tapi ada penambahan dalam enkripsi datanya. Trims…

  19. david wong permalink

    klo boleh minta source code lengkap video conference java
    send k davidwong87@yahoo.com thx a lot

  20. Dudy Arsfin permalink

    mas…minta source code lengkap yah…buat SKRIPSI nih urgent banget.
    kirim ke email: kafelemon@gmail.com

  21. tedi permalink

    mas minta souce code ma penjelasannya ya ke tedi_awaludin@yahoo.com, klw bisa di kasi LINK buat downloadnya ya mas…..thank’s

  22. Loser permalink

    Percuma kalau Source gak di share, buat apa bagi ilmu kayak gini…

  23. ari permalink

    mas tolong kirim sourcenya ya buat referensi tugas
    thanx
    priyoari293@gmail.com

  24. inuy permalink

    mas.,tolong minta source codenya lengkpnya kirim ke email saya donk,..inuy_treeny@yahoo,com
    cz lg cari refensi buat ngerjain skripsi…makasih ya mas,
    ato masny kn bs buat bukunya ke penerbit,..kn lumayan :)

  25. farid ghozi permalink

    mas saya butuh source code sama flowchartx buat tugas akhir saya.bisa dikirimkan ke e-mail saya g’mas?sebelumnya aku ucpin mkasih.

    e-mailq:zieva_c4hkdr@yaho.co.id

  26. William permalink

    Mas, bisa minta tolong kirim source codenya yg lengkap ke email saya… Jusshinshu@hotmail.com.. ayo bagi2 ilmu :)
    makasih ya~~

  27. uba permalink

    Mas ,
    nice tutorial, tp mash mentok neh
    klo boleh minta tolong kirim source code lengkap video conference java
    soalnya mau buat TA bulan ini.
    email ku : uba_pbt@yahoo.com
    trimakasih mas

  28. mas, bisa tolong kirimin source codenya yg lengkap sama flowchartx buat tugas akhir saya.bisa dikirimkan ke e-mail saya g’mas?

    Email ku: Ranuyogaarsyiandi@ymail.com
    Soalnya saya mau buat TA Bulan ini…..
    sebelumnya aku ucpin mkasih.

  29. ady permalink

    dear ,, saya ady dari jogja …

    saya sudah berhasil untuk capture video dan audionya dan bisa menyimpan.
    tapi saya masih bingung soal Transmit RTP JMF nya … mohon untuk bisa share sourcode nya ke email saya : 4lk4l1@gmail.com

    trimakasih sebelumnya

  30. mhinie permalink

    mas minta dong source codenya ke mhiniecute@gmail.com soalnya penting banget nih mas untuk tugas akhir….trims

  31. wah…. mantab mas, boleh minta sourchnya ga???
    kirim ke email sy ya.. : hamdanlabkom[at]yahoo.com
    skalian add ym sy ya mas,sy pengin bisa sharing sm mas… hehe

  32. Acip permalink

    mas, saya lgi cari trainer java tk pelatihan java dgn study kasus video conference di instansi pemerintah. hub saya di 0818180374 acip segera or acipsukirno@yahoo.com

  33. tukangjava permalink

    UNTUK SEMUANYA
    saya sudah lama tidak program ini. tapi saya coba upload source code saya dulu sewaktu mengerjakan.
    bisa coba download di

    http://iyeyo.com/JVConfv1.0.rar

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.