JMF捕获技术(音频)

JMF捕获技术(音频)

 

JMF可以捕获语音和视频设备,也就是利用JMF可以控制麦克、摄像头这些音视频设备,在这里要讨论的是如何利用JMF来让麦克工作,在自己的机器上测试,让你听到自己的声音。

 

下面是要涉及到的主要的类:

 

CaptureDeviceManagerCaptureDeviceInfoVectorMediaPlayerDataSourceMeidaLocatorAduioFormatVideoFormatFormat

 

可以在Sun公司提供的Document上查阅,也可以下下来,网址记不住了。可以先看一下,有个初步的了解,然后看完例子再回来看类库,这样可能会好一些。

 

public class CaptureDeviceManager

extends java.lang.Object

CaptureDeviceManager is a manager class that provides access to a list of the capture devices available on a system. CaptureDeviceManager uses a registry and query mechanisms to locate devices and return CaptureDeviceInfo objects for available devices. The CaptureDeviceManager is also used to register new capture devices.

 

public class CaptureDeviceInfo

extends java.lang.Object

implements java.io.Serializable

A CaptureDeviceInfo object contains information about a particular capture device.

public class MediaPlayer

extends java.awt.Container

implements Player, java.io.Externalizable

MediaPlayer encapsulates a player in a JavaBeansTM component. MediaPlayer implements the Player and Externalizable interfaces.

A MediaPlayer can be used as a full-featured Player with either the default Player controls or custom controls.

 

 

还会涉及到一个监听接口:

 

ControllerListener。这个主要是用来监听媒体播放器的接口的。

 

1、捕获音频设备

/*

 * @author : kenny

 */

import javax.media.*;

....................

public class CaptureAudio {

 

Vector deviceList = new Vector();

AudioForamt audio = new AudioFormat(AudioFormat.LINEAR);

Format audioFormat = (Format)audio;

    MediaPlayer player = null;

    MediaLocator locator = null;

    CaptureDeviceInfo captureInfo ;

   

public CaptureAudio() {

deviceList = CaptureDeviceManager.getDeviceList(audioFormat);

captureInfo = (CaptureDeviceInfo)deviceList.get(0);

locator = captureInfo.getLocator();

    }

 

    public void play() {

player = new MediaPlayer();

player.setMediaLocator(locator);

player.addControllerListener(this);

 

player.realize();

    }

 

 

public void controllerUpdate(ControllerEvent e) {

       if(e instanceof RealizeCompleteEvent)

           player.prefetch();

       if(e instanceof PrefetchCompleteEvent)

           player.start();

}

 

public static void main(String[] args) {

    CaptureAudio audio = new CaptureAudio();

    audio.play();

}

}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值