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

📄 mediacomponent.java

📁 j2me设计的界面包
💻 JAVA
字号:
/*
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Sun designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Sun in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */
package com.sun.lwuit;

import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;
import com.sun.lwuit.geom.*;

/**
 * A component allowing us to embed and control rich media content
 * 
 * @author Nir Shabi
 */
public class MediaComponent extends Component {

    private Player player;
    private VideoControl vidc;

    /** 
     * Creates a new instance of MediaComponent 
     * 
     * @param player the media player
     */
    public MediaComponent(Player player) {
        this.player = player;
        if(player.getState() < player.REALIZED){
            throw new IllegalArgumentException("player must be in a realized state");
        }
        vidc = (VideoControl)Display.getInstance().getVideoControl(player);
    }

    /**
     * @inheritDoc
     */
    protected void initComponent() {
        getComponentForm().registerMediaComponent(this);
    }

    /**
     * @inheritDoc
     */
    protected void deinitialize() {
        getComponentForm().deregisterMediaComponent(this);
    }
    
    
    /**
     * @inheritDoc
     */
    public void paint(Graphics g) {
        vidc.setDisplayLocation(g.getTranslateX() + getX(), g.getTranslateY() + getY());  
    }

    /**
     * @inheritDoc
     */
    protected Dimension calcPreferredSize() {
        return new Dimension(vidc.getSourceWidth(), vidc.getSourceHeight());
    }

    /**
     * @inheritDoc
     */
    public void setWidth(int width) {
        super.setWidth(width);
        try {
            vidc.setDisplaySize(width, vidc.getDisplayHeight());
        } catch (MediaException ex) {
            ex.printStackTrace();
        }

    }

    /**
     * @inheritDoc
     */
    public void setHeight(int height) {
        super.setHeight(height);
        try {
            vidc.setDisplaySize(vidc.getDisplayWidth(), height);
        } catch (MediaException ex) {
            ex.printStackTrace();
        }
    }

    /**
     * Display the embedded media component
     * 
     * @param visible true to display, false to hide
     */
    public void setVisible(boolean visible) {
        if (vidc != null) {
            vidc.setVisible(visible);
        }
    }

    /**
     * Start media playback implicitly setting the component to visible
     * 
     * @throws javax.microedition.media.MediaException
     */
    public void start() throws MediaException {
        vidc.setVisible(true);
        player.start();
    }

    /**
     * Stope media playback 
     */
    public void stop() throws MediaException {
        player.stop();
    }

    /**
     * Set the number of times the media should loop
     * 
     * @param count the number of times the media should loop
     */
    public void setLoopCount(int count) {
        player.setLoopCount(count);
    }

    /**
     * Return the duration of the media
     * 
     * @return the duration of the media
     */
    public long getMediaTime() {
        return player.getMediaTime();
    }

    /**
     * "Jump" to a point in time within the media
     * 
     * @param now the point in time to "Jump" to
     * @throws javax.microedition.media.MediaException
     */
    public long setMediaTime(long now) throws MediaException {
        return player.setMediaTime(now);
    }

}

⌨️ 快捷键说明

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