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

📄 jmstudio.java

📁 java 开发的sip软电话 源码 jain sip
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        }
        else if ( strCmd.equals(MENU_FILE_OPENURL) ) {
            openUrl ();
        }
        else if ( strCmd.equals(MENU_FILE_OPENRTP) ) {
            openRtp ();
        }
        else if ( strCmd.equals(MENU_FILE_CAPTURE) ) {
            captureMedia ();
        }
        else if ( strCmd.equals(MENU_FILE_RECENTURL) ) {
            if ( objSource instanceof JMenuItem ) {
                nameUrl = ((JMenuItem)objSource).getText ();
                open ( nameUrl );
            }
        }
        else if ( strCmd.equals(MENU_FILE_CLOSE) ) {
            killCurrentPlayer ();
//            setPlaceholder ();
        }
        else if ( strCmd.equals(MENU_FILE_EXPORT) ) {
            exportMedia ();
        }
        else if ( strCmd.equals(MENU_FILE_TRANSMIT) ) {
            transmitMedia ();
        }
        else if ( strCmd.equals(MENU_FILE_PREFERENCES) ) {
            if ( jmfRegistry == null )
                jmfRegistry = new JMFRegistry ();
            jmfRegistry.setVisible ( true );
            jmfRegistry.addWindowListener(
                new WindowAdapter () {
                    public void windowClosing ( WindowEvent event ) {
                        Vector  vector;
                        vector = CaptureDeviceManager.getDeviceList ( null );
                        if ( vector == null  ||  vector.size() < 1 )
                            menuCapture.setEnabled ( false );
                        else
                            menuCapture.setEnabled ( true );
                    }
                }
            );
        }
        else if ( strCmd.equals(MENU_FILE_EXIT) ) {
            closeAll ();
        }

        else if ( strCmd.equals(MENU_PLAYER_AUTOPLAY) ) {
        }
        else if ( strCmd.equals(MENU_PLAYER_AUTOLOOP) ) {
        }
        else if ( strCmd.equals(MENU_PLAYER_KEEPASPECT) ) {
        }
        else if ( strCmd.equals(MENU_PLAYER_FULLSCREEN) ) {
            setFullScreen ( true );
        }
        else if ( strCmd.equals(MENU_PLAYER_SNAPSHOT) ) {
            doSnapShot ();
        }
        else if ( strCmd.equals(MENU_PLAYER_PLUGINS) ) {
            if ( componentPlugins != null ) {
                componentPlugins.setVisible ( true );
            }
            else {
                if ( controlPlugins != null  &&  controlPlugins instanceof Component ) {
                    componentPlugins = (Component)controlPlugins;
                    componentPlugins.setVisible ( true );
                    component = componentPlugins;
                    while ( component != null ) {
                        if ( component instanceof Frame ) {
                            frame = (Frame) component;
                            JMFrame.autoPosition ( frame, this );
                            break;
                        }
                        component = component.getParent ();
                    }
                }
            }
        }
        else if ( strCmd.equals(MENU_PLAYER_CAPTURE) ) {
            if ( dlgCaptureControls != null ) {
                dlgCaptureControls.setVisible ( true );
                dlgCaptureControls.toFront ();
            }
        }
        else if ( strCmd.equals(MENU_PLAYER_RTPSESSION) ) {
            if ( dlgSessionControl != null ) {
                dlgSessionControl.setVisible ( true );
                dlgSessionControl.toFront ();
            }
        }
        else if ( strCmd.equals(MENU_PLAYER_TRANSMISSION) ) {
            if ( dlgTransmissionStats != null ) {
                dlgTransmissionStats.setVisible ( true );
                dlgTransmissionStats.toFront ();
            }
        }
        else if ( strCmd.equals(MENU_HELP_ABOUT) ) {
            AboutDialog.createDialog ( this );
        }
        else {
            super.actionPerformed ( event );
        }
    }

    public void itemStateChanged ( ItemEvent event ) {
        Object      objSource;

        objSource = event.getSource ();
        if ( objSource == menuAutoPlay ) {
            if ( cfgJMApps != null )
                cfgJMApps.setAutoPlay ( menuAutoPlay.getState() );
        }
        else if ( objSource == menuAutoLoop ) {
            if ( mediaPlayerCurrent != null )
                mediaPlayerCurrent.setPlaybackLoop ( menuAutoLoop.getState() );
            if ( cfgJMApps != null )
                cfgJMApps.setAutoLoop ( menuAutoLoop.getState() );
        }
        else if ( objSource == menuKeepAspect ) {
            if ( mediaPlayerCurrent != null ) {
                mediaPlayerCurrent.setFixedAspectRatio ( menuKeepAspect.getState() );
                if ( panelVideo != null )
                    panelVideo.resizeVisualComponent ();
            }
            if ( cfgJMApps != null )
                cfgJMApps.setKeepAspectRatio ( menuKeepAspect.getState() );
        }
    }

    public void windowClosing ( WindowEvent event ) {
    killCurrentPlayer();
        this.dispose ();
    }

    public void windowClosed ( WindowEvent event ) {
        int     nIndex;
        Point   pointLocation;

        super.windowClosed ( event );

        if ( frameSnap != null )
            frameSnap.dispose ();
        if ( vectorFrames.contains(this) ) {
            pointLocation = this.getLocation ();
            nIndex = vectorFrames.indexOf ( this );
            if ( cfgJMApps != null )
                cfgJMApps.setJMStudioFrameLocation ( pointLocation, nIndex );
            vectorFrames.removeElement ( this );
        }
        if ( vectorFrames.size() < 1 )
            exitApllication ();
    }

    public synchronized void update ( ReceiveStreamEvent event) {
        ReceiveStream   stream;
        RTPSessionMgr   mngrSession;
        DataSource      dataSource;
        PlayerFrame     frame;

        if ( event instanceof NewReceiveStreamEvent ) {
        recvRTP = true;
            mngrSession = (RTPSessionMgr)event.getSource();
            stream =((NewReceiveStreamEvent)event).getReceiveStream ();
            dataSource = stream.getDataSource ();

        // this call is not valid for the new RTP interface
            //strOptionalTitle = mngrSession.getSessionAddress().getDataAddress().getHostAddress()
            //                     + ":" + mngrSession.getSessionAddress().getDataPort();

        strOptionalTitle = hostAddress + ":" + port;

            mngrSessionRtp = null;
            if ( vectorRtpFrames != null  &&  vectorMngrSessions != null
                        &&  vectorMngrSessions.size() > 0
                        &&  vectorMngrSessions.firstElement() == mngrSession ) {
                frame = new PlayerFrame ( this, strOptionalTitle );
                vectorRtpFrames.addElement ( frame );
                frame.open ( dataSource );
                frame.setVisible ( true );
            }
            else {
                open ( dataSource, false );

                vectorMngrSessions = new Vector ();
                vectorMngrSessions.addElement ( mngrSession );
                vectorStreams = new Vector ();
                vectorStreams.addElement ( stream );

                dlgSessionControl = new SessionControlDialog ( this, mngrSession );
                updateMenu ();

                vectorRtpFrames = new Vector ();
            }
        }
    }

    protected void processRealizeComplete ( RealizeCompleteEvent event ) {
        String      strMediaLocation;
        Dimension   dimVideo;
        Dimension   dimControlPanel;

        killCurrentView ();

        this.setCursor ( cursorNormal );

        // Get the visual component
        panelVideo = new VideoPanel ( mediaPlayerCurrent );
        panelVideo.setZoom ( dDefaultScale );
        panelVideo.addMenuZoomActionListener ( this );
        // Get the control component
    compControl = mediaPlayerCurrent.getControlPanelComponent ();

        // The bounds of the components will be set by LayoutManager,
        // but the components might start draw themselves in another thread
        // causing the garbage on the screen.
        // So we set here their bounds to avoid it.
        dimVideo = panelVideo.getPreferredSize ();
    //        panelVideo.setBounds ( 0, 0, dimVideo.width, dimVideo.height );
    if ( compControl != null ) {
            dimControlPanel = compControl.getPreferredSize ();
            compControl.setBounds ( 0, dimVideo.height, dimVideo.width, dimControlPanel.height );
        }

        panelContent.add ( panelVideo, BorderLayout.CENTER );
    //        panelVideo.repaint ();
    if ( compControl != null) {
            panelContent.add ( compControl, BorderLayout.SOUTH );
            compControl.repaint ();
    }

        // Plug-In Viewer - Implementation specific control
        controlPlugins = mediaPlayerCurrent.getControl ( "com.sun.media.JMD" );
        controlGrabber = (FrameGrabbingControl) mediaPlayerCurrent.getControl ( "javax.media.control.FrameGrabbingControl" );


    // Wait for visual to show up
    Component compVis = panelVideo.getVisualComponent();
    if (compVis != null) {
        while (!compVis.isVisible()) {
        try {
            Thread.sleep(10);
        } catch (InterruptedException ie) {
        }
        }
    }

    // Ask the player to prefetch data and prepare to start.
    mediaPlayerCurrent.prefetch ();

    strMediaLocation = mediaPlayerCurrent.getMediaLocation ();
    if ( strMediaLocation == null  ||  strMediaLocation.trim().length() < 1 )
            strMediaLocation = strOptionalTitle;
    setTitle ( strMediaLocation + " - " + APPNAME );

    updateMenu ();
    }

    protected void processPrefetchComplete ( PrefetchCompleteEvent event ) {
        long    lWait;

        if ( menuAutoPlay.getState() ) {
            if ( mediaPlayerCurrent != null  &&  mediaPlayerCurrent.getTargetState() != Controller.Started ) {
                mediaPlayerCurrent.start();
            }
        }
    }

    protected void processFormatChange ( FormatChangeEvent event ) {
        killCurrentView ();

        // Get the visual component
        panelVideo = new VideoPanel ( mediaPlayerCurrent );
        panelVideo.setZoom ( dDefaultScale );
        panelVideo.addMenuZoomActionListener ( this );
        panelContent.add ( panelVideo, BorderLayout.CENTER );

        // Get the control component
        compControl = mediaPlayerCurrent.getControlPanelComponent ();
        if ( compControl != null) {
            panelContent.add ( compControl, BorderLayout.SOUTH );
        }
    }

    private void openFile () {
        String          nameFile = null;
        String          nameUrl;
        MediaPlayer     mediaPlayer;
        boolean         boolResult;

        if ( dlgOpenFile == null )
            dlgOpenFile = new JFileChooser ();

        if ( cfgJMApps != null )
            nameFile = cfgJMApps.getLastOpenFile ();
        if ( nameFile != null )
            dlgOpenFile.setSelectedFile ( new File(nameFile) );

        if( dlgOpenFile.showOpenDialog (this) != JFileChooser.APPROVE_OPTION)
            return;

        File selectedFile = dlgOpenFile.getSelectedFile ();

        if ( cfgJMApps != null )
            cfgJMApps.setLastOpenFile ( selectedFile.getAbsolutePath() );

        open ( selectedFile.toURI().toString() );
    }

    private void openUrl () {
        OpenUrlDialog   dlgOpenUrl;
        String          nameUrl = null;
        MediaPlayer     mediaPlayer;
        boolean         boolResult;
        String          strAction;

        if ( cfgJMApps != null )
            nameUrl = cfgJMApps.getLastOpenUrl ();

        dlgOpenUrl = new OpenUrlDialog ( this, nameUrl );
        dlgOpenUrl.setVisible(true);
        strAction = dlgOpenUrl.getAction ();
        if ( !strAction.equals(JMDialog.ACTION_OPEN) )
            return;
        nameUrl = dlgOpenUrl.getUrl ();
        if ( nameUrl == null )
            return;

        if ( cfgJMApps != null )
            cfgJMApps.setLastOpenUrl ( nameUrl );
        open ( nameUrl );
    }

    private String hostAddress;
    private String port;
    RTPTimer rtptimer = null;

    class RTPTimer extends Thread {
    JMStudio outer = null;
    public RTPTimer(JMStudio outer) {
        this.outer = outer;
    }

    public void run() {
        MessageDialog dlg = null;
        String newtime;
        String answer = "";
        Image image = null;

        try {
        Thread.sleep(7000);
        } catch (InterruptedException ie) {
        return;
        }

        //System.out.println("killed = " + killed);
        //System.out.println("recvRTP = " + recvRTP);

        if ( !killed && !recvRTP) {
        // popup a info diag
        image = ImageArea.loadImage ( "iconInfo.gif" );
        dlg = new MessageDialog(outer, "Waiting for data", "7 seconds elasped", image, false,false);
        dlg.setLocationCenter ();
        dlg.setVisible(true);
        }

        int count = 7;
        while ( !killed && !recvRTP && !Thread.currentThread().isInterrupted() && count < 60 ) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ie) {
            if ( dlg != null ) {
            dlg.dispose();
            dlg = null;
            }
            return;
        }

        count ++;
        newtime = new Integer(count).toString() + " seconds elasped";
        if ( dlg != null )
            dlg.getTextView().setText(newtime);
        } // end of while

        if ( !killed && !recvRTP && !Thread.currentThread().isInterrupted()) {

        answer = MessageDialog.createYesNoDialog (outer, "Waing for data", "You have been waiting for 60 secs. Continue to wait?");

        }

        if ( !killed && !recvRTP && !Thread.currentThread().isInterrupted() && answer.equals("No")) {
        if ( dlg != null ) {
            dlg.dispose();
            dlg = null;
        }

        outer.killCurrentPlayer();
        return;
        }

        count = 60;
        while ( !killed && !recvRTP && !Thread.currentThread().isInterrupted()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ie) {
            if ( dlg != null ) {

⌨️ 快捷键说明

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