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

📄 exportwizard.java

📁 里面是关于jmf编程的例子,希望能给初学者带来一些帮助
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }        catch ( Exception exception ) {            stopSaving ();            MessageDialog.createErrorDialog ( frameOwner, exception );            return ( false );        }        try {            dataSinkSave.addDataSinkListener( this );            monitorControl = (MonitorControl)            processor.getControl("javax.media.control.MonitorControl");            if (monitorControl != null)                monitor = monitorControl.getControlComponent();            Time duration = processor.getDuration();            nMediaDuration = (int)duration.getSeconds();            dataSinkSave.open ();            dataSinkSave.start ();            processor.start ();            //dataSource.start ();            if ( nMediaDuration > 0                    &&  duration != Duration.DURATION_UNBOUNDED                    &&  duration != Duration.DURATION_UNKNOWN )                dlgProgressSave = new ProgressDialog ( frameOwner,						       JMFI18N.getResource("jmstudio.saveprogress.title"),						       0, nMediaDuration, this );            else                dlgProgressSave = new ProgressDialog ( frameOwner,						       JMFI18N.getResource("jmstudio.saveprogress.title"),						       JMFI18N.getResource("jmstudio.saveprogress.label"),						       monitor, this );            dlgProgressSave.setVisible ( true );            threadProgressSave = new ProgressThread ( processor, dlgProgressSave );            threadProgressSave.start ();            vectorWindowsLeft.addElement ( dlgProgressSave );        }        catch ( Exception exception ) {            stopSaving ();            MessageDialog.createErrorDialog ( frameOwner, exception );        }        return ( true );    }    private boolean doTransmit () {        int                     i;        DataSource              dsOutput;        MediaLocator            mediaDest;        Object                  arrControls[];        int                     nMediaDuration;        String                  strFileName;        PushBufferStream        arrStreams [];        boolean                 boolSucceeded;        boolean                 arrAudioEnabled [];        boolean                 arrVideoEnabled [];        String                  arrVideoAddresses [];        String                  arrAudioAddresses [];        String                  arrVideoPorts [];        String                  arrAudioPorts [];        String                  arrVideoTtls [];        String                  arrAudioTtls [];        SessionManager          managerSession;        SendStream              streamSend;        TrackControl            arrTrackControls [];        Format                  format;        int                     nVideoIndex;        int                     nAudioIndex;        String                  strAddress;        String                  strPort;        String                  strTtl;        String                  strStreamLabel;        String                  strAudio = JMFI18N.getResource("jmstudio.export.targetnw.audio");        String                  strVideo = JMFI18N.getResource("jmstudio.export.targetnw.video");        if ( processor == null )            return ( false );        panelTargetFormat.updateProcessorFormat ();        realizeProcessor ();        if ( processor == null )            return ( false );        dsOutput = processor.getDataOutput ();        if ( dsOutput == null ) {            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.creatednooutput") );            destroyProcessor ();            return ( false );        }        if ( !(dsOutput instanceof PushBufferDataSource) ) {            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.outputincorrect") );            destroyProcessor ();            return ( false );        }        arrStreams = ((PushBufferDataSource)dsOutput).getStreams ();        if (arrStreams == null) {            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.outputempty") );            destroyProcessor ();            return ( false );        }        arrVideoEnabled = panelTargetFormat.getEnabledVideoTracks ();        arrAudioEnabled = panelTargetFormat.getEnabledAudioTracks ();        arrVideoAddresses = panelTargetNetwork.getVideoAddresses ();        arrAudioAddresses = panelTargetNetwork.getAudioAddresses ();        arrVideoPorts = panelTargetNetwork.getVideoPorts ();        arrAudioPorts = panelTargetNetwork.getAudioPorts ();        arrVideoTtls = panelTargetNetwork.getVideoTtls ();        arrAudioTtls = panelTargetNetwork.getAudioTtls ();        arrTrackControls = processor.getTrackControls ();        nVideoIndex = 0;        nAudioIndex = 0;        boolSucceeded = false;        for ( i = 0;  i < arrStreams.length;  i++ ) {            format = arrStreams[i].getFormat ();            if ( format instanceof VideoFormat ) {                while ( (nVideoIndex < arrVideoEnabled.length) &&			arrVideoEnabled[nVideoIndex] == false )                    nVideoIndex++;		if (nVideoIndex >= arrVideoEnabled.length)		    continue;                strAddress = arrVideoAddresses[nVideoIndex];                strPort = arrVideoPorts[nVideoIndex];                strTtl = arrVideoTtls[nVideoIndex];                nVideoIndex++;                strStreamLabel = strVideo + " " + nVideoIndex;            } else if ( format instanceof AudioFormat ) {                while ( (nAudioIndex < arrAudioEnabled.length) &&			arrAudioEnabled[nAudioIndex] == false )                    nAudioIndex++;		if (nAudioIndex >= arrAudioEnabled.length)		    continue;                strAddress = arrAudioAddresses[nAudioIndex];                strPort = arrAudioPorts[nAudioIndex];                strTtl = arrAudioTtls[nAudioIndex];                nAudioIndex++;                strStreamLabel = strAudio + " " + nAudioIndex;            } else                continue;            try {                if ( strAddress.equals("...")  ||  strPort.equals("") )                    continue;                managerSession = JMFUtils.createSessionManager ( strAddress, strPort, strTtl );                if ( managerSession == null ) {                    MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.createsessionmanager") );                    destroyProcessor ();                    return ( false );                }                streamSend = managerSession.createSendStream ( dsOutput, i );                streamSend.start();                if ( !boolSucceeded ) {                    createTransmitWindow ();                }                boolSucceeded = true;                addTransmitSessionManager ( managerSession, streamSend, strStreamLabel );            } catch ( Exception exception ) {                MessageDialog.createErrorDialog ( frameOwner, exception );                destroyProcessor ();                return ( false );            }        }        dlgCaptureControls = panelSource.getCaptureControlsDialog ();        if ( dlgCaptureControls != null  &&  !dlgCaptureControls.isEmpty() ) {            dlgCaptureControls.setVisible ( true );        }        if ( !boolSucceeded ) {            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.transmittracks") );            destroyProcessor ();        }        return ( boolSucceeded );    }    protected void createTransmitWindow () {        if ( processor == null )            return;        playerTransmit = new TransmitPlayerWindow ( processor );        playerTransmit.addWindowListener ( this );        vectorWindowsLeft.addElement ( playerTransmit );    }    protected void addTransmitSessionManager ( SessionManager mngrSession,                        SendStream streamSend, String strStreamLabel ) {        if ( playerTransmit == null )            return;        playerTransmit.addSessionManager ( mngrSession, streamSend, strStreamLabel );    }    private boolean doPreview () {        DataSource    dsOutput;        Player        player;        PlayerWindow  windowPlayer;        if ( processor == null )            return ( false );        panelTargetFormat.updateProcessorFormat ();        realizeProcessor ();        if ( processor == null )            return ( false );        dsOutput = processor.getDataOutput ();        if ( dsOutput == null ) {            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.creatednooutput") );            destroyProcessor ();            return ( false );        }        // Create a Player with the data source        // Create a PlayerWindow for the Player (this will start the player)        // Start the processor        try {            player = Manager.createPlayer ( dsOutput );            if ( player != null ) {                windowPlayer = new PlayerWindow ( player, JMFI18N.getResource("jmstudio.playerwindow.preview") );                vectorWindowsLeft.addElement ( windowPlayer );                windowPlayer = new PlayerWindow ( processor, JMFI18N.getResource("jmstudio.playerwindow.transcoding") );                vectorWindowsLeft.addElement ( windowPlayer );            }            else {                MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.player.create") );                destroyProcessor ();                return ( false );            }        }        catch ( Exception exception ) {            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.player.create"), exception );            destroyProcessor ();            return ( false );        }        return ( true );    }    public void actionPerformed ( ActionEvent event ) {        String        strCmd;        Object        objectSource;        strCmd = event.getActionCommand ();        if ( (strCmd.equals(ProgressDialog.ACTION_ABORT)                        ||  strCmd.equals(ProgressDialog.ACTION_STOP))                        &&  dataSinkSave != null ) {            stopSaving ();        }        else if ( strCmd.equals(ProgressDialog.ACTION_PAUSE) &&  dataSinkSave != null ) {            processor.stop ();            dlgProgressSave.setPauseButtonText ( ProgressDialog.ACTION_RESUME );            threadProgressSave.pauseThread ();        }        else if ( strCmd.equals(ProgressDialog.ACTION_RESUME) &&  dataSinkSave != null ) {            processor.start ();            dlgProgressSave.setPauseButtonText ( ProgressDialog.ACTION_PAUSE );            threadProgressSave.resumeThread ();        }        else            super.actionPerformed ( event );    }    public void controllerUpdate ( ControllerEvent event ) {        if ( event instanceof ControllerErrorEvent ) {            strFailMessage = JMFI18N.getResource ( "jmstudio.error.controller" )                    + "\n" + ((ControllerErrorEvent)event).getMessage ();//            MessageDialog.createErrorDialogModeless ( frameOwner, strFailMessage );        }        else if (event instanceof EndOfMediaEvent) {            if ( strTargetType.equals(PanelMediaTargetType.TYPE_FILE) )                stopSaving();        }    }    public void dataSinkUpdate(DataSinkEvent event) {        if ( event instanceof EndOfStreamEvent ) {            closeDataSink();//            MessageDialog.createInfoDialog ( frameOwner, "File has been saved." );        } else if ( event instanceof DataSinkErrorEvent ) {            stopSaving();            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.writefile") );        }    }    public void windowClosed ( WindowEvent event ) {        Object          objSource;        objSource = event.getSource ();        if ( objSource == playerTransmit ) {            if ( dlgCaptureControls != null ) {                dlgCaptureControls.dispose ();                dlgCaptureControls = null;            }            playerTransmit = null;        }        if ( getAction().equals(WizardDialog.ACTION_CANCEL) )            destroyProcessor ();    }    private void stopSaving () {        if ( threadProgressSave != null ) {            threadProgressSave.terminateNormaly ();            threadProgressSave = null;        }        if ( processor != null ) {            processor.stop ();            destroyProcessor ();        }        if ( dlgProgressSave != null ) {            dlgProgressSave.dispose ();            dlgProgressSave = null;        }    }    private synchronized void closeDataSink() {        if (dataSinkSave != null) {            dataSinkSave.close ();            dataSinkSave = null;        }    }    class StateListener implements ControllerListener {        public void controllerUpdate(ControllerEvent ce) {            if ( ce instanceof ControllerClosedEvent )                stateFailed = true;            if ( ce instanceof ControllerEvent ) {                synchronized (stateLock) {                    stateLock.notifyAll();                }            }        }    }}

⌨️ 快捷键说明

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