2009年1月22日

The Java Media Framework API (JMF) Capture microphone & camera

The Java Media Framework API (JMF)
MediaPlayer Bean

import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.protocol.DataSource;
import javax.swing.JApplet;

public class Main extends JApplet {

Player player = null;

public void init() {
this.setSize(800, 600);
try {
DataSource ds = Manager.createMergingDataSource(new DataSource[]{
// Microphone
Manager.createDataSource(new MediaLocator("javasound://0")),
// Camera
Manager.createDataSource(new MediaLocator("vfw://0"))
});
player = Manager.createRealizedPlayer(ds);
player.start();
this.add(player.getVisualComponent());
} catch (Exception e) {
e.printStackTrace();
}
}

public void destroy() {
if (player != null) {
player.stop();
player.close();
}
super.destroy();
}

}

沒有留言:

網誌存檔