⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 micojmf.java

📁 jmf的入门级小程序
💻 JAVA
字号:
import javax.media.*;
import javax.media.bean.playerbean.MediaPlayer;
import javax.media.format.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import java.io.*;


import java.util.*;

public class Micojmf implements ControllerListener {
	
	BufferedInputStream playbackInputStream;
	Vector deviceList = new Vector();//声明一个向量

	AudioFormat audio = new AudioFormat(AudioFormat.LINEAR);//设定为LINEAR压缩格式

	Format audioFormat = (Format) audio;//音频格式

	MediaPlayer player = null;

	MediaLocator locator = null;//describes the location of media content

	CaptureDeviceInfo captureInfo;

	public Micojmf() {

		deviceList = CaptureDeviceManager.getDeviceList(audioFormat);//获得特定Format的驱动列表
		
		if(deviceList == null || deviceList.size() < 1 ) { 

		    System.out.println("未捕获到音频设备,请检查设备是否正确连接"); } 

		captureInfo = (CaptureDeviceInfo) deviceList.get(0);//捕获驱动信息

		locator = captureInfo.getLocator();//获得驱动的位置
	

	}

	public void play() {

		player = new MediaPlayer();

		player.setMediaLocator(locator);

		player.addControllerListener(this);

		player.realize();//The realize method puts the Controller into 
						//the Realizing state and returns immediately
	}

	public void controllerUpdate(ControllerEvent e) {

		if (e instanceof RealizeCompleteEvent)//响应realizeCompleteEvent事件
			
			player.prefetch();//处理DATA减少start()的反应时间

		if (e instanceof PrefetchCompleteEvent)
			
			player.start();//启动player对象
		
		if(e instanceof ControllerClosedEvent) {
	        player.stop();
	        player.close(); 
	        } 


	}

	public static void main(String[] args) {

		//CaptureAudio audio = new CaptureAudio();
		Micojmf audios=new Micojmf();

		audios.play();

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -