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

📄 playerframe.java

📁 里面是关于jmf编程的例子,希望能给初学者带来一些帮助
💻 JAVA
字号:
/* * @(#)PlayerFrame.java	1.6 00/05/12 * * 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.ui;import java.net.*;import java.lang.reflect.Method;import java.awt.*;import java.awt.event.*;import javax.media.*;import javax.media.protocol.*;import javax.media.format.*;import javax.media.bean.playerbean.*;import com.sun.media.util.JMFI18N;public class PlayerFrame extends JMFrame implements ActionListener,                                        ContainerListener, ControllerListener {    protected MediaPlayer       mediaPlayerCurrent = null;    protected JMPanel           panelContent;    protected Component         compControl = null;    protected VideoPanel        panelVideo = null;    protected ImageArea         areaImagePlaceholder = null;    protected Component         progressBarCache = null;    protected Cursor            cursorNormal = new Cursor ( Cursor.DEFAULT_CURSOR );    protected Cursor            cursorWait = new Cursor ( Cursor.WAIT_CURSOR );    protected boolean           boolErrorClose = false;    protected boolean           boolMediaClosed = true;    public PlayerFrame ( Frame frameOwner, String strTitle ) {        super ( frameOwner, strTitle );    }    protected void initFrame () {        super.initFrame ();        this.setLayout ( new BorderLayout() );        panelContent = new JMPanel ( new BorderLayout() );        this.add ( panelContent, BorderLayout.CENTER );        panelContent.addContainerListener ( this );        setPlaceholder ();    }    public void open ( String nameUrl ) {        MediaPlayer     mediaPlayer;        boolean         boolResult;        mediaPlayer = jmapps.util.JMFUtils.createMediaPlayer ( nameUrl, (Frame)this );        boolResult = open ( mediaPlayer );    }    public void open ( DataSource dataSource ) {        MediaPlayer     mediaPlayer;        boolean         boolResult;        mediaPlayer = jmapps.util.JMFUtils.createMediaPlayer ( dataSource, (Frame)this );        boolResult = open ( mediaPlayer );    }    public boolean open ( MediaPlayer mediaPlayer ) {        if ( mediaPlayer == null )            return ( false );        killCurrentPlayer ();        this.setCursor ( cursorWait );        mediaPlayerCurrent = mediaPlayer;        mediaPlayer.setPopupActive ( false );        mediaPlayer.setControlPanelVisible ( false );        mediaPlayer.addControllerListener ( this );        mediaPlayer.realize();        return ( true );    }    public void setPlaceholder () {        Image   image;        if ( areaImagePlaceholder == null ) {            image = ImageArea.loadImage ( "playerPlaceholder.gif", (Component)this, true );            if ( image != null ) {                areaImagePlaceholder = new ImageArea ( image );                areaImagePlaceholder.setInsets ( 0, 0, 0, 0 );            }        }        if ( areaImagePlaceholder != null ) {            panelContent.removeAll ();            panelContent.add ( areaImagePlaceholder, BorderLayout.CENTER );        }    }    protected void killCurrentView () {        int         i;        Component   component;        panelVideo = null;        compControl = null;        i = panelContent.getComponentCount();        while ( i > 0 ) {            i--;            component = panelContent.getComponent ( i );            if ( component == areaImagePlaceholder )                continue;            panelContent.remove ( component );        }    }    protected void killCurrentPlayer () {        int                     i;        int                     nCount;        killCurrentView ();//        progressBarCache = null;        if ( mediaPlayerCurrent != null ) {            boolMediaClosed = false;            mediaPlayerCurrent.close ();            if ( boolErrorClose == false ) {                while ( boolMediaClosed == false ) {                    try {                        Thread.sleep ( 50 );                    }                    catch ( Exception exception ) {                    }                }            }            mediaPlayerCurrent.removeControllerListener ( this );            mediaPlayerCurrent = null;        }    }    public void actionPerformed ( ActionEvent event ) {        String      strCmd;        Object      objSource;        strCmd = event.getActionCommand ();        objSource = event.getSource ();        if ( strCmd == null  &&  objSource instanceof MenuItem )            strCmd = ((MenuItem)objSource).getActionCommand ();        if ( strCmd == null )            return;        if ( strCmd.equals(VideoPanel.MENU_ZOOM_1_2) ) {            pack ();        }        else if ( strCmd.equals(VideoPanel.MENU_ZOOM_1_1) ) {            pack ();        }        else if ( strCmd.equals(VideoPanel.MENU_ZOOM_2_1) ) {            pack ();        }        else if ( strCmd.equals(VideoPanel.MENU_ZOOM_4_1) ) {            pack ();        }    }    public synchronized void controllerUpdate ( ControllerEvent event ) {        if ( event instanceof RealizeCompleteEvent ) {            processRealizeComplete ( (RealizeCompleteEvent) event );        }        else if ( event instanceof PrefetchCompleteEvent ) {            processPrefetchComplete ( (PrefetchCompleteEvent) event );        }        else if ( event instanceof ControllerErrorEvent ) {            processControllerError ( (ControllerErrorEvent) event );        }        else if ( event instanceof ControllerClosedEvent ) {            processControllerClosed ( (ControllerClosedEvent) event );        }        else if ( event instanceof DurationUpdateEvent ) {            Time t = ((DurationUpdateEvent)event).getDuration();        }        else if ( event instanceof CachingControlEvent ) {            processCachingControl ( (CachingControlEvent) event );        }        else if ( event instanceof StartEvent ) {        }        else if ( event instanceof MediaTimeSetEvent ) {        }        else if ( event instanceof TransitionEvent ) {        }        else if ( event instanceof RateChangeEvent ) {        }        else if ( event instanceof StopTimeChangeEvent ) {        }        else if ( event instanceof FormatChangeEvent ) {            processFormatChange ( (FormatChangeEvent) event );        }        else if ( event instanceof SizeChangeEvent ) {        }        else if ( event.getClass().getName().endsWith("ReplaceURLEvent") ) {            processReplaceURL ( event );        }    }    protected void processRealizeComplete ( RealizeCompleteEvent event ) {        killCurrentView ();        this.setCursor ( cursorNormal );        panelVideo = new VideoPanel ( mediaPlayerCurrent );        panelVideo.setZoom ( 1.0 );        panelVideo.addMenuZoomActionListener ( this );        panelContent.add ( panelVideo, BorderLayout.CENTER );        compControl = mediaPlayerCurrent.getControlPanelComponent ();        if ( compControl != null) {            panelContent.add ( compControl, BorderLayout.SOUTH );        }        mediaPlayerCurrent.prefetch ();	}    protected void processPrefetchComplete ( PrefetchCompleteEvent event ) {        mediaPlayerCurrent.start();    }    protected void processControllerError ( ControllerErrorEvent event ) {        String      strMessage;        this.setCursor ( cursorNormal );        strMessage = JMFI18N.getResource ( "jmstudio.error.controller" )                    + "\n" + event.getMessage();        MessageDialog.createErrorDialogModeless ( this, strMessage );        if ( boolMediaClosed == true ) {            boolErrorClose = true;            killCurrentPlayer ();            boolErrorClose = false;        }        boolMediaClosed = true;    }    protected void processControllerClosed ( ControllerClosedEvent event ) {        boolMediaClosed = true;        this.setCursor ( cursorNormal );    }    protected void processCachingControl ( CachingControlEvent event ) {        CachingControl      controlCaching;        Component           progressBarCacheNew = null;        controlCaching = event.getCachingControl ();        if ( controlCaching == null )            return;        if ( progressBarCacheNew == null )            progressBarCacheNew = controlCaching.getControlComponent();        if ( progressBarCacheNew == null )            progressBarCacheNew = controlCaching.getProgressBarComponent();        if ( progressBarCacheNew == null )            return;        if ( progressBarCacheNew == progressBarCache )            return;        if ( mediaPlayerCurrent != null  &&  mediaPlayerCurrent.getState() >= Player.Realized )            return;        killCurrentView ();        progressBarCache = progressBarCacheNew;        panelContent.add ( progressBarCache, BorderLayout.CENTER );        this.setCursor ( cursorNormal );    }    protected void processFormatChange ( FormatChangeEvent event ) {        killCurrentView ();        // Get the visual component        panelVideo = new VideoPanel ( mediaPlayerCurrent );        panelVideo.setZoom ( 1.0 );        panelVideo.addMenuZoomActionListener ( this );        panelContent.add ( panelVideo, BorderLayout.CENTER );        // Get the control component        compControl = mediaPlayerCurrent.getControlPanelComponent ();        if ( compControl != null) {            panelContent.add ( compControl, BorderLayout.SOUTH );        }    }    protected void processReplaceURL ( ControllerEvent event ) {        Class   classReplaceURLEvent;        Class   classEvent;        Method  methodGetUrl;        URL     url;        killCurrentPlayer ();        try {            classReplaceURLEvent = Class.forName ( "com.ibm.media.ReplaceURLEvent" );            classEvent = event.getClass ();            classReplaceURLEvent.isAssignableFrom ( classEvent );            methodGetUrl = classEvent.getMethod ( "getURL", null );            url = (URL) methodGetUrl.invoke ( event, null );            open ( url.toString() );        }        catch (Exception e) {        }        catch (Error e) {        }    }    public void componentAdded ( ContainerEvent event ) {        if ( event.getChild() != areaImagePlaceholder                        &&  areaImagePlaceholder != null                        &&  areaImagePlaceholder.getParent() == panelContent )            panelContent.remove ( areaImagePlaceholder );        this.pack();    }    public void componentRemoved ( ContainerEvent event ) {        if ( panelContent.getComponentCount() < 1                        &&  event.getChild() != areaImagePlaceholder )            setPlaceholder ();        else            this.pack ();    }    public void windowClosed ( WindowEvent event ) {        killCurrentPlayer ();    }    public void windowClosing ( WindowEvent event ) {        this.setVisible ( false );    }}

⌨️ 快捷键说明

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