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

📄 capturedialog.java

📁 里面是关于jmf编程的例子,希望能给初学者带来一些帮助
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @(#)CaptureDialog.java	1.1 00/02/10 * * Copyright (c) 1999 Sun Microsystems, Inc. All Rights Reserved. * * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use, * modify and redistribute this software in source and binary code form, * provided that i) this copyright notice and license appear on all copies of * the software; and ii) Licensee does not utilize the software in a manner * which is disparaging to Sun. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * This software is not designed or intended for use in on-line control of * aircraft, air traffic, aircraft navigation or aircraft communications; or in * the design, construction, operation or maintenance of any nuclear * facility. Licensee represents and warrants that it will not use or * redistribute the Software for such purposes. */package jmapps.jmstudio;import java.util.Vector;import java.net.*;import java.awt.*;import java.awt.event.*;import javax.media.*;import javax.media.format.*;import javax.media.protocol.*;import javax.media.control.*;import com.sun.media.util.JMFI18N;import com.sun.media.ui.TabControl;import com.sun.media.ui.AudioFormatChooser;import com.sun.media.ui.VideoFormatChooser;import jmapps.ui.*;import jmapps.util.*;public class CaptureDialog extends JMDialog implements ItemListener {    private JMAppsCfg           cfgJMApps;    private Vector              vectorDevices = null;    private Vector              vectorAudioDevices = null;    private Vector              vectorVideoDevices = null;    private Panel               panelDevices;    private Checkbox            checkUseVideo = null;    private Checkbox            checkUseAudio = null;    private Choice              comboVideoDevice = null;    private Choice              comboAudioDevice = null;    private Panel               panelVideoFormat = null;    private Panel               panelAudioFormat = null;    private AudioFormatChooser  chooserAudio = null;    private VideoFormatChooser  chooserVideo = null;    private Button              buttonOK;    private Button              buttonCancel;    public CaptureDialog ( Frame parentFrame, JMAppsCfg cfgJMApps ) {        super ( parentFrame, JMFI18N.getResource("jmstudio.capture.title"), true );        this.cfgJMApps = cfgJMApps;        try {            init();        }        catch (Exception e) {            e.printStackTrace();        }    }    public boolean isVideoDeviceUsed () {        boolean         boolUsed = false;        if ( checkUseVideo != null )            boolUsed = checkUseVideo.getState ();        return ( boolUsed );    }    public boolean isAudioDeviceUsed () {        boolean         boolUsed = false;        if ( checkUseAudio != null )            boolUsed = checkUseAudio.getState ();        return ( boolUsed );    }    public CaptureDeviceInfo getVideoDevice () {        int                     i;        CaptureDeviceInfo       infoCaptureDevice = null;        if ( comboVideoDevice != null  &&  isVideoDeviceUsed() ) {            i = comboVideoDevice.getSelectedIndex ();            infoCaptureDevice = (CaptureDeviceInfo) vectorVideoDevices.elementAt ( i );        }        return ( infoCaptureDevice );    }    public CaptureDeviceInfo getAudioDevice () {        int                     i;        CaptureDeviceInfo       infoCaptureDevice = null;        if ( comboAudioDevice != null  &&  isAudioDeviceUsed() ) {            i = comboAudioDevice.getSelectedIndex ();            infoCaptureDevice = (CaptureDeviceInfo) vectorAudioDevices.elementAt ( i );        }        return ( infoCaptureDevice );    }    public VideoFormat getVideoFormat () {        VideoFormat    format = null;        if ( chooserVideo != null  &&  isVideoDeviceUsed() )            format = (VideoFormat) chooserVideo.getFormat ();        return ( format );    }    public AudioFormat getAudioFormat () {        AudioFormat    format = null;        if ( chooserAudio != null  &&  isAudioDeviceUsed() )            format = (AudioFormat) chooserAudio.getFormat ();        return ( format );    }    public DataSource createCaptureDataSource () {        DataSource          dataSource = null;        String              audioDeviceName = null;        String              videoDeviceName = null;        CaptureDeviceInfo   cdi;        cdi = getAudioDevice();        if (cdi != null && isAudioDeviceUsed())            audioDeviceName = cdi.getName();        cdi = getVideoDevice();        if (cdi != null && isVideoDeviceUsed())            videoDeviceName = cdi.getName();        dataSource = JMFUtils.createCaptureDataSource(audioDeviceName,						      getAudioFormat(),						      videoDeviceName,						      getVideoFormat());        return ( dataSource );    }    private void init () throws Exception {        Panel       panel;        Panel       panelButtons;        JMPanel     panelContent;        Label       label;        this.setLayout ( new BorderLayout() );        panelContent = new JMPanel ( new BorderLayout() );        panelContent.setEmptyBorder ( 6, 6, 6, 6 );        panelContent.setBackground ( Color.lightGray );        this.add ( panelContent, BorderLayout.CENTER );        vectorDevices = CaptureDeviceManager.getDeviceList ( null );        if ( vectorDevices == null  ||  vectorDevices.size() < 1 ) {            label = new Label ( JMFI18N.getResource("jmstudio.capture.nodevices") );            panelContent.add ( label, BorderLayout.CENTER );        }        else {            panelDevices = new Panel ( new GridLayout(1,0,6,6) );            panelContent.add ( panelDevices, BorderLayout.CENTER );            panel = createVideoPanel ();            if ( panel != null )                panelDevices.add ( panel );            panel = createAudioPanel ();            if ( panel != null )                panelDevices.add ( panel );        }        panel = new JMPanel ( new FlowLayout(FlowLayout.CENTER) );        panelContent.add ( panel, BorderLayout.SOUTH );        if ( vectorDevices != null  &&  vectorDevices.size() > 0 )            panelButtons = createButtonPanel ( new String[] { ACTION_OK, ACTION_CANCEL } );        else            panelButtons = createButtonPanel ( new String[] { ACTION_OK } );        panel.add ( panelButtons );        this.pack ();        this.setResizable ( false );    }    private Panel createVideoPanel () throws Exception {        int                 i, j;        int                 nCount;        JMPanel             panelVideo;        JMPanel             panelContent;        Panel               panel;        Panel               panelTemp;        CaptureDeviceInfo   infoCaptureDevice;        Format              arrFormats [];        boolean             boolState = true;        VideoFormat         formatDefault = null;        String              strDeviceName;        boolean             boolContains;        JMAppsCfg.CaptureDeviceData   dataCapture = null;        nCount = vectorDevices.size ();        vectorVideoDevices = new Vector ();        for ( i = 0;  i < nCount;  i++ ) {            infoCaptureDevice = (CaptureDeviceInfo) vectorDevices.elementAt ( i );            arrFormats = infoCaptureDevice.getFormats ();            for ( j = 0;  j < arrFormats.length;  j++ ) {                if ( arrFormats[j] instanceof VideoFormat ) {                    vectorVideoDevices.addElement ( infoCaptureDevice );                    break;                }            }        }        if ( vectorVideoDevices.isEmpty() )            return ( null );        if ( cfgJMApps != null )            dataCapture = cfgJMApps.getLastCaptureVideoData();        if ( dataCapture!= null ) {            boolState = dataCapture.boolUse;            if ( dataCapture.format instanceof VideoFormat )                formatDefault = (VideoFormat) dataCapture.format;        }        panelVideo = new JMPanel ( new BorderLayout(6,6) );        panelVideo.setEtchedBorder ();        panelContent = new JMPanel ( new BorderLayout(6,6) );        panelContent.setEmptyBorder ( 6, 6, 6, 6 );        panelVideo.add ( panelContent, BorderLayout.CENTER );        panel = panelContent;        panelTemp = new Panel ( new BorderLayout(6,6) );        panel.add ( panelTemp, BorderLayout.NORTH );        checkUseVideo = new Checkbox ( JMFI18N.getResource("jmstudio.capture.video.usedevice"), boolState );        checkUseVideo.addItemListener ( this );        panelTemp.add ( checkUseVideo, BorderLayout.WEST );        panelTemp = new Panel ( new BorderLayout(6,6) );        panel.add ( panelTemp, BorderLayout.CENTER );

⌨️ 快捷键说明

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