《2022年java视频播放器源代码 .pdf》由会员分享,可在线阅读,更多相关《2022年java视频播放器源代码 .pdf(3页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、import java.awt.*; import java.io.*; import java.util.*; import javax.media.*; import javax.media.format.*; import javax.swing.*; publicclass VideoPlayerer implements ControllerListener Vector audioCapDevList = null; Vector videoCapDevList = null; CaptureDeviceInfo audioCapDevInfo = null; CaptureDev
2、iceInfo videoCapDevInfo = null; MediaLocator audioCapDevLoc = null; MediaLocator videoCapDevLoc = null; Player audioPlayer; Player videoPlayer; publicvoid initAudioCapDevLoc() /这里可以填写其它的音频编码格式,具体请看AudioFormat类audioCapDevList = CaptureDeviceManager.getDeviceList( newAudioFormat( AudioFormat.LINEAR );
3、 if (audioCapDevList.size() 0) /或许有几个 CaptureDevice,这里取第一个audioCapDevInfo = (CaptureDeviceInfo) audioCapDevList.elementAt(0); audioCapDevLoc = audioCapDevInfo.getLocator(); else System.out .println( 找不到音频采集设备 ); System.exit(0); publicvoid initVideoCapDevLoc() /这里可以填写其它的编码视频格式,具体请看VideoFormat类videoCa
4、pDevList = CaptureDeviceManager.getDeviceList( new名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 3 页 - - - - - - - - - VideoFormat( VideoFormat.YUV); if (videoCapDevList.size() 0) /或许有几个 CaptureDevice,这里取第一个videoCapDevInfo = (CaptureDeviceInfo) videoCapDevList.
5、elementAt(0); videoCapDevLoc = videoCapDevInfo.getLocator(); else System.out .println( 找不到视频采集设备 ); System.exit(0); publicvoid initAudioPlayer() try audioPlayer = Manager.createPlayer( audioCapDevLoc); catch (NoPlayerException ex) catch (IOException ex) /增加一个侦听器,侦听player状态的改变audioPlayer.addControlle
6、rListener(this); audioPlayer.realize(); publicvoid initVideoPlayer() try videoPlayer = Manager.createPlayer( videoCapDevLoc); catch (NoPlayerException ex) catch (IOException ex) /增加一个侦听器,侦听player状态的改变videoPlayer.addControllerListener(this); videoPlayer.realize(); publicvoid stopAndClosePlayer() audi
7、oPlayer.stop(); audioPlayer.close(); videoPlayer.stop(); videoPlayer.close(); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 3 页 - - - - - - - - - publicsynchronizedvoid controllerUpdate(ControllerEvent ce) Player p = (Player) ce.getSourceController(); JFrame j
8、Frame = new JFrame(); Component com; if (p = null) return; /如果 player的状态变为 Realizedif (ce instanceof RealizeCompleteEvent) if (com = p.getControlPanelComponent() != null) jFrame.add(com, BorderLayout.SOUTH); if (com = p.getVisualComponent() != null) jFrame.add(com, BorderLayout.NORTH); jFrame.setVis
9、ible(true); jFrame.pack(); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE ); p.start(); publicstaticvoid main(String args) /主函数VideoPlayer cap = new VideoPlayer(); cap.initAudioCapDevLoc(); cap.initVideoCapDevLoc(); cap.initAudioPlayer(); cap.initVideoPlayer(); try Thread.currentThread().sleep(20000);/20秒后停止并关闭播放器 catch (InterruptedException ex) cap.stopAndClosePlayer(); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 3 页 - - - - - - - - -