关闭

JMF捕获技术(音频)

2491人阅读 评论(0) 收藏 举报

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();

}

}

 

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:77848次
    • 积分:1057
    • 等级:
    • 排名:千里之外
    • 原创:21篇
    • 转载:8篇
    • 译文:2篇
    • 评论:37条
    文章分类
    最新评论