亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? videorecorder.java

?? 是一個用java實現的
?? JAVA
字號:
/*
 * VideoRecorder.java
 * 
 * Created on Mar 16, 2004
 *
 */
package gov.nist.applet.phone.media.messaging;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Vector;

import javax.media.CaptureDeviceInfo;
import javax.media.CaptureDeviceManager;
import javax.media.ConfigureCompleteEvent;
import javax.media.Controller;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.EndOfMediaEvent;
import javax.media.Format;
import javax.media.IncompatibleSourceException;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.MediaTimeSetEvent;
import javax.media.PrefetchCompleteEvent;
import javax.media.Processor;
import javax.media.RealizeCompleteEvent;
import javax.media.ResourceUnavailableEvent;
import javax.media.SizeChangeEvent;
import javax.media.StopAtTimeEvent;
import javax.media.StopByRequestEvent;
import javax.media.control.TrackControl;
import javax.media.datasink.DataSinkErrorEvent;
import javax.media.datasink.DataSinkEvent;
import javax.media.datasink.DataSinkListener;
import javax.media.datasink.EndOfStreamEvent;
import javax.media.format.VideoFormat;
import javax.media.protocol.ContentDescriptor;
import javax.media.protocol.DataSource;
import javax.media.protocol.FileTypeDescriptor;

/**
 * Class allowing one to record some audio in a buffer
 * Play only MPEG_AUDIO and GSM audio data
 * With some minor modifications can play RAW data also
 * 
 * @author Jean Deruelle <jean.deruelle@nist.gov>
 *
 * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
 */
public class VideoRecorder implements ControllerListener, DataSinkListener, Runnable{
	Processor p;
	Object waitSync = new Object();
	boolean stateTransitionOK = true;
	static boolean monitorOn = false;
	private MediaLocator videoLocator=null;	
	boolean bufferingDone = false;
	RawDataSourceHandler handler =null;
	Thread recorderThread=null;		
	DataSource ds = null;
	/**
	 * get the devices for the audio capture and print their formats
	 */
	protected void initialize() {		
		CaptureDeviceInfo videoCDI=null;
		Vector captureDevices=null;
		captureDevices= CaptureDeviceManager.getDeviceList(null);
		System.out.println("- number of capture devices: "+captureDevices.size() );
		CaptureDeviceInfo cdi=null;
		for (int i = 0; i < captureDevices.size(); i++) {
			cdi = (CaptureDeviceInfo) captureDevices.elementAt(i);		
			Format[] formatArray=cdi.getFormats();
			for (int j = 0; j < formatArray.length; j++) {
				Format format=formatArray[j];				
			   if (format instanceof VideoFormat) {
					if (videoCDI == null) {
						videoCDI=cdi;
					}
			   }			   
			}
		}
		if(videoCDI!=null)
			videoLocator=videoCDI.getLocator();
	}

	/**
	 * Set the format of the tracks
	 * either to MPEG_AUDIO or GSM
	 */
	protected void setTrackFormat(){
		//Get the tracks from the processor
		TrackControl[] tracks = p.getTrackControls();

		// Do we have atleast one track?
		if (tracks == null || tracks.length < 1)
	 		System.out.println("Couldn't find tracks in processor");
	 		
		// Set the output content descriptor to GSM
		// This will limit the supported formats reported from
		// Track.getSupportedFormats to only valid AVI formats.
		//p.setContentDescriptor(new FileTypeDescriptor(FileTypeDescriptor.MPEG_AUDIO));
		p.setContentDescriptor(new ContentDescriptor(ContentDescriptor.RAW));
		
		Format supported[];
		Format chosen=null;
	 	boolean atLeastOneTrack = false;
		
		// Program the tracks.
		for (int i = 0; i < tracks.length; i++) {
			Format format = tracks[i].getFormat();
			if (tracks[i].isEnabled()) {
				supported = tracks[i].getSupportedFormats();
				/*System.out.println("track : "+ i);
				for(int j=0;j<supported.length;j++)
				System.out.println("Supported format : "+supported[j].getEncoding());*/
				// We've set the output content to the GSM.            
				if (supported.length > 0) {
					for(int j=0;j<supported.length;j++){
						System.out.println("Supported format : "+supported[j].toString().toLowerCase());
				 		if (supported[j] instanceof VideoFormat) {
							if(supported[j].toString().toLowerCase().indexOf("rgb")!=-1){
								chosen = supported[j];  
								break;
							}
						}
					}
					if(chosen!=null){
						tracks[i].setFormat(chosen);                
						System.err.println("Track " + i + " is set to transmit as:");
						System.err.println("  " + chosen);
						atLeastOneTrack = true;
					}
					else{
						System.err.println("Track " + i + " is set to transmit as nothing");
					}
				} else
					tracks[i].setEnabled(false);
			} else
				tracks[i].setEnabled(false);
		}
	}

	/**
	 * Given a DataSource, create a processor and hook up the output
	 * DataSource from the processor to a customed DataSink.
	 * @return false if something wrong happened
	 */
	protected boolean record() {		
		// Create a DataSource given the media locator.
		try {
			ds = Manager.createDataSource(videoLocator);
		} catch (Exception e) {
			System.err.println("Cannot create DataSource from: " + videoLocator);
			return false;
		}		
		
		try {
			p = Manager.createProcessor(ds);
		} catch (Exception e) {
			System.err.println("Failed to create a processor from the given DataSource: " + e);
			return false;
		}

		p.addControllerListener(this);

		// Put the Processor into configured state.
		p.configure();
		if (!waitForState(Processor.Configured)) {
			System.err.println("Failed to configure the processor.");
			return false;
		}
		setTrackFormat();
		/*ContentDescriptor[] descriptors = p.getSupportedContentDescriptors();
		for (int n = 0; n < descriptors.length; n++) {
			System.out.println("Desc: " + descriptors[n].toString());
		}*/
		// Get the raw output from the processor.
		//p.setContentDescriptor(new ContentDescriptor(ContentDescriptor.RAW));
		//p.setContentDescriptor(new FileTypeDescriptor(FileTypeDescriptor.MPEG_AUDIO));
		p.realize();
		if (!waitForState(Controller.Realized)) {
			System.err.println("Failed to realize the processor.");
			return false;
		}
		
		// Get the output DataSource from the processor and
		// hook it up to the RawDataSourceHandler.
		DataSource ods = p.getDataOutput();
		handler = new RawDataSourceHandler();

		try {
			handler.setSource(ods);
		} catch (IncompatibleSourceException e) {
			System.err.println("Cannot handle the output DataSource from the processor: " + ods);
			//return false;
		}
		System.err.println("Start datasource handler ");
		handler.addDataSinkListener(this);
		try{
			handler.setSource(ds);
			handler.start();
		}
		catch(IncompatibleSourceException ioe){
			ioe.printStackTrace();
		}
		System.err.println("Prefetch the processor ");
		// Prefetch the processor.
		p.prefetch();
		if (!waitForState(Controller.Prefetched)) {
			System.err.println("Failed to prefetch the processor.");
			return false;
		}		
		// Start the processor.
		p.start();			
		System.err.println("processor started");				

		return true;
	}

	/**
	 * Block until file writing is done. 
	 */
	/*private boolean waitForFileDone(double duration) {		
		synchronized (waitFileSync) {
			try {
				while (!bufferingDone) {
					if(p.getMediaTime().getSeconds() > duration)
						p.close();
					waitFileSync.wait(500);
					System.err.print(".");
				}
			} catch (Exception e) {}
		}
		bufferingDone=false;
		return true;
	}*/		
	
	/**
	 * Block until the processor has transitioned to the given state.
	 * @param state - the state to wait for
	 * @return false if the transition failed.
	 */
	protected boolean waitForState(int state) {
		synchronized (waitSync) {
			try {
			while (p.getState() < state && stateTransitionOK)
				waitSync.wait();
			} catch (Exception e) {}
		}
		return stateTransitionOK;
	}

	/**
	 * Stop the voice recording
	 */
	public void stop(){
		p.stop();
		bufferingDone=true;		
	}
	
	/**
	 * Start the voice recording
	 */
	public void start(){
		initialize();
		if(recorderThread==null){
			recorderThread=new Thread(this);
			recorderThread.setName("Voice Recorder Thread");
		}
			
		recorderThread.start();			
	}
	
	/**
	 * the process of recording the voice
	 */
	public void run(){
		boolean succeeded=record();
		if(!succeeded)
			return;
		while(!bufferingDone){
			try{
				recorderThread.sleep(1);
			}
			catch(InterruptedException ie){
				ie.printStackTrace();
			}
		}	
		try{
			Thread.sleep(100);
		}
		catch(InterruptedException ie){
			ie.printStackTrace();
		}	
		//Clean up
		System.err.println("closing datasource" );
		try{
			ds.stop();
		}
		catch(IOException ioe){
			ioe.printStackTrace();
		}
		ds.disconnect();						
		System.err.println("closing processor" );
		p.close();
		p.removeControllerListener(this);
		recorderThread=null;
		System.err.println("closing handler" );
		handler.close();		
		System.err.println("...done Buffering.");
		bufferingDone=false;
	}

	/**
	 * Controller Listener Method.
	 * Allow one to know what happen on the recorder and the voice
	 * @param evt - event received 
	 */
	public void controllerUpdate(ControllerEvent evt) {
		//System.out.println("new Event received"+evt.getClass().getName());
		if (evt instanceof ConfigureCompleteEvent ||
			evt instanceof RealizeCompleteEvent ||
			evt instanceof PrefetchCompleteEvent) {
			synchronized (waitSync) {
				stateTransitionOK = true;
				waitSync.notifyAll();
			}
		} else if (evt instanceof ResourceUnavailableEvent) {
			synchronized (waitSync) {
				stateTransitionOK = false;
				waitSync.notifyAll();
			}
		} else if (evt instanceof EndOfMediaEvent) {
			System.err.println("closing datasource" );
			try{
				ds.stop();
			}
			catch(IOException ioe){
				ioe.printStackTrace();
			}
			ds.disconnect();						
			System.err.println("closing controller");
			evt.getSourceController().close();
			//Clean up
			System.err.println("closing processor" );
			p.close();
			p.removeControllerListener(this);
			recorderThread=null;
			System.err.println("closing handler" );
			handler.close();		
			System.err.println("...done Buffering.");
			bufferingDone=true;
		} else if (evt instanceof SizeChangeEvent) {
		}
		else if (evt instanceof MediaTimeSetEvent) {
			System.err.println("- mediaTime set: " + 
			((MediaTimeSetEvent)evt).getMediaTime().getSeconds());
		} else if (evt instanceof StopAtTimeEvent) {
			System.err.println("- stop at time: " +
			((StopAtTimeEvent)evt).getMediaTime().getSeconds());
			//Clean up
			System.err.println("closing datasource" );
			try{
				ds.stop();
			}
			catch(IOException ioe){
				ioe.printStackTrace();
			}
			ds.disconnect();						
			System.err.println("closing controller");
			evt.getSourceController().close();
			System.err.println("closing processor" );
			p.close();
			p.removeControllerListener(this);
			recorderThread=null;
			System.err.println("closing handler" );
			handler.close();		
			System.err.println("...done Buffering.");
			bufferingDone=true;
		}
		else if (evt instanceof StopByRequestEvent) {				
			//			Clean up
		  System.err.println("closing datasource" );
		  try{
			  ds.stop();
		  }
		  catch(IOException ioe){
			  ioe.printStackTrace();
		  }
		  ds.disconnect();
			System.err.println("closing controller");
			evt.getSourceController().close();						
		  	System.err.println("closing processor" );
		  	p.close();
		  	p.removeControllerListener(this);
		  	recorderThread=null;
		  	System.err.println("closing handler" );
		  	handler.close();		
		  	System.err.println("...done Buffering.");
		}
	}

	/**
	 * Get the recorded voice buffer 
	 * @return the voice recorded in an array of bytes
	 */
	public byte[] getRecord(){
		return handler.getRecordBuffer();
	}

	/**
	 * DataSink Listener
	 * @param evt - event received  
	 */
	public void dataSinkUpdate(DataSinkEvent evt) {

		if (evt instanceof EndOfStreamEvent) {
			bufferingDone = true;	
			//waitFileSync.notifyAll();
			System.err.println("All done!");
			evt.getSourceDataSink().close();
			//System.exit(0);
		}
		else if (evt instanceof DataSinkErrorEvent) {
			//synchronized (waitFileSync) {
			bufferingDone = true;	
			evt.getSourceDataSink().close();			
				//waitFileSync.notifyAll();
			//}
		}
	}

	/**
	 * Utility method to write a recorded voice buffer to a file
	 * @param data -  the recorded voice
	 */
	private static void writeBufferToFile(byte[] data){
		File f=new File("F://test.mov");
		FileOutputStream fos=null;
		try{
			fos=new FileOutputStream(f);
		}
		catch(FileNotFoundException fnfe){
			fnfe.printStackTrace();
		}
		try{
			fos.write(data);
		}
		catch(IOException ioe){
			ioe.printStackTrace();
		}
	}

	/**
	 * Main program
	 * @param args - 
	 */
	public static void main(String [] args) {
		VideoRecorder videoRecorder = new VideoRecorder();
		VideoPlayer videoPlayer=new VideoPlayer();	
		//for(int i=0;i<2;i++){
			videoRecorder.start();		
			try{
				Thread.sleep(5000);
			}
			catch(InterruptedException ie){
				ie.printStackTrace();
			}
			videoRecorder.stop();				
			videoPlayer.initialize(videoRecorder.getRecord());
			videoPlayer.play();	
			try{
				Thread.sleep(5000);
			}
			catch(InterruptedException ie){
				ie.printStackTrace();
			}				
		//}
		writeBufferToFile(videoRecorder.getRecord());
	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
青青草伊人久久| 久久综合色8888| 欧美日韩日日骚| 久久久影视传媒| 午夜精品久久久久久久99水蜜桃| 国产一区二区0| 欧美精品久久天天躁| 国产精品嫩草影院av蜜臀| 丝袜a∨在线一区二区三区不卡| 懂色av中文字幕一区二区三区| 欧美高清视频www夜色资源网| 成人欧美一区二区三区白人| 精品亚洲成a人| 91精品国产综合久久小美女| 一级特黄大欧美久久久| 成人99免费视频| 国产日韩av一区| 国产一区二区三区香蕉 | 国产精品自在欧美一区| 精品视频资源站| 亚洲欧美日韩综合aⅴ视频| 成人黄色在线看| 国产调教视频一区| 国产在线视频一区二区| 精品欧美一区二区在线观看 | 国产精品91一区二区| 精品美女一区二区| 九色综合国产一区二区三区| 欧美一区二区在线观看| 丝袜亚洲精品中文字幕一区| 欧美日韩国产色站一区二区三区| 国产美女在线观看一区| 日韩一区二区影院| 美女被吸乳得到大胸91| 欧美一区二区日韩| 久热成人在线视频| 精品国产乱码久久久久久夜甘婷婷| 午夜精品久久久久| 日韩视频在线观看一区二区| 六月丁香婷婷久久| 精品国产乱码久久久久久牛牛| 理论片日本一区| 久久影院电视剧免费观看| 国产精品中文字幕一区二区三区| 久久久综合视频| 99久久99久久精品免费观看| 一区二区三区中文在线| 欧美欧美欧美欧美| 久久电影网电视剧免费观看| 精品粉嫩超白一线天av| 国产福利91精品一区二区三区| 久久久久久麻豆| 91丨porny丨中文| 无码av中文一区二区三区桃花岛| 欧美一级黄色大片| 丁香激情综合五月| 一区二区三区四区不卡视频| 欧美精品粉嫩高潮一区二区| 国产在线不卡一区| 一色屋精品亚洲香蕉网站| 精品婷婷伊人一区三区三| 激情深爱一区二区| 亚洲女厕所小便bbb| 欧美一级高清片| 成人性生交大片免费看中文网站| 亚洲午夜影视影院在线观看| 精品国产91洋老外米糕| 粉嫩av一区二区三区粉嫩 | 国产精品高潮呻吟久久| 欧美三级在线看| 极品美女销魂一区二区三区 | 色婷婷久久久综合中文字幕| 视频一区视频二区中文字幕| 国产丝袜美腿一区二区三区| 欧美日韩一区成人| 欧美日韩精品一二三区| 国产精品1区2区3区在线观看| 亚洲激情图片qvod| 久久久久久久久久久久久夜| 日本高清不卡在线观看| 精品欧美一区二区久久| 不卡免费追剧大全电视剧网站| 亚洲成av人在线观看| 中文文精品字幕一区二区| 欧美日韩aaa| 91亚洲国产成人精品一区二区三| 免费一级欧美片在线观看| 中文字幕亚洲一区二区va在线| 欧美一级精品在线| 欧美午夜片在线观看| kk眼镜猥琐国模调教系列一区二区| 青青青爽久久午夜综合久久午夜| 亚洲视频免费看| 国产日韩欧美精品综合| 欧美一级电影网站| 欧美视频一区二区三区在线观看| 丁香一区二区三区| 国产麻豆精品theporn| 日本成人在线一区| 午夜精品一区二区三区免费视频 | 成人动漫中文字幕| 国产一区91精品张津瑜| 久久国产夜色精品鲁鲁99| 亚洲成人tv网| 亚洲高清不卡在线| 一区二区三区不卡视频| 亚洲免费观看高清完整| 中文字幕五月欧美| 国产精品私人影院| 日本一区二区视频在线| 久久精品视频一区二区三区| 精品国产露脸精彩对白| 精品乱人伦小说| 欧美成人午夜电影| 日韩一区二区三区高清免费看看| 91精品欧美综合在线观看最新| 欧美在线制服丝袜| 欧美日韩免费一区二区三区| 欧美吻胸吃奶大尺度电影| 欧美性受xxxx黑人xyx性爽| 欧美亚洲综合在线| 欧美日韩一区二区三区四区| 欧美日韩二区三区| 日韩欧美成人一区| 久久精品免费在线观看| 国产欧美日韩三级| 国产精品第五页| 一区二区三区在线播放| 北条麻妃一区二区三区| 成人av小说网| 在线视频综合导航| 欧美精品自拍偷拍| 欧美va天堂va视频va在线| 久久免费视频色| 亚洲天天做日日做天天谢日日欢| 国产精品福利av| 亚洲成人动漫在线免费观看| 日本欧美韩国一区三区| 国产一区二区三区在线看麻豆 | 九九视频精品免费| 国产成人免费xxxxxxxx| 一本高清dvd不卡在线观看| 欧美手机在线视频| 精品欧美一区二区三区精品久久| 亚洲国产成人自拍| 亚洲第一狼人社区| 国产一区二区三区免费播放 | 高清成人在线观看| 91黄色激情网站| 日韩一区二区免费视频| 国产欧美视频一区二区| 婷婷中文字幕一区三区| 国产精品主播直播| 欧美三级电影在线观看| 久久久亚洲精品一区二区三区| 亚洲欧美一区二区视频| 日本人妖一区二区| 91农村精品一区二区在线| 欧美一区二区三区小说| 国产精品免费网站在线观看| 婷婷成人激情在线网| 成人午夜电影小说| 欧美一区二区精品| 亚洲欧美aⅴ...| 国内外成人在线| 欧美二区在线观看| 亚洲天堂久久久久久久| 国产在线不卡一卡二卡三卡四卡| 色诱视频网站一区| 国产日韩影视精品| 美女网站一区二区| 欧美三级电影精品| 中文字幕一区二区5566日韩| 另类小说欧美激情| 91麻豆精品91久久久久同性| 亚洲欧美激情一区二区| 国产精品一二二区| 日韩一区二区精品葵司在线| 一区二区三区中文免费| av在线免费不卡| 国产精品网站导航| 国产精品99久久久久久宅男| 欧美大片在线观看一区二区| 亚洲一区自拍偷拍| 久久久精品免费网站| 日韩高清中文字幕一区| 欧美在线一区二区三区| 亚洲日本在线a| av午夜一区麻豆| 中文欧美字幕免费| 国产老妇另类xxxxx| 欧美xxxx老人做受| 久久综合综合久久综合| 日韩一级黄色片| 日本亚洲视频在线| 欧美一区二区三区思思人| 亚洲国产综合人成综合网站| 欧美综合一区二区三区| 伊人夜夜躁av伊人久久| 在线亚洲+欧美+日本专区|