JMF捕获技术(视频)

最近由于项目要求要获取视频.

在网上找了些代码又对其修改.

这个是视频类.

package com.cayden.video; import java.awt.Component; import java.awt.Frame; import java.awt.Panel; import java.io.IOException; import javax.media.CaptureDeviceInfo; import javax.media.CaptureDeviceManager; import javax.media.ControllerEvent; import javax.media.ControllerListener; import javax.media.Manager; import javax.media.MediaLocator; import javax.media.NoPlayerException; import javax.media.Player; import javax.media.PrefetchCompleteEvent; import javax.media.RealizeCompleteEvent; import javax.media.bean.playerbean.MediaPlayer; import javax.swing.JFrame; class CaptureVideo extends JFrame implements ControllerListener { private CaptureDeviceInfo infor ; private MediaLocator mediaLocator ; private String url = "vfw:Microsoft WDM Image Capture (Win32):0"; private Component com; private Panel panel ; Player player; public CaptureVideo() { infor = CaptureDeviceManager.getDevice(url); mediaLocator = infor.getLocator(); } public void player() { try { player =Manager.createPlayer(mediaLocator);//利用mediaLocator创建Player player.addControllerListener(this); player.realize(); } catch (NoPlayerException e) { // TODO 自动生成 catch 块 e.printStackTrace(); } catch (IOException e) { // TODO 自动生成 catch 块 e.printStackTrace(); } } public void createComponent() { setTitle("视频信号"); setBounds(100,100,640,480); panel = new Panel(); if((com = player.getVisualComponent()) != null) { panel.add(com); } add(panel); setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public synchronized void controllerUpdate(ControllerEvent arg0) { // TODO 自动生成方法存根 if(arg0 instanceof RealizeCompleteEvent) { System.out.println("realized"); createComponent(); //将播放器添加到Panel上 player.prefetch(); } if(arg0 instanceof PrefetchCompleteEvent) { player.start(); System.out.println("prefetched"); } } }

下面的是测试类

package com.cayden.video; public class Test { public static void main(String[] args) { CaptureVideo video = new CaptureVideo(); video.player(); } }

参考网址:

http://www.wangchao.net.cn/bbsdetail_793851.html

 

你可能感兴趣的:(String,image,Microsoft,video,url,Class)