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

📄 videotest.java

📁 索爱的多媒体例程,包括播放音乐,视频等
💻 JAVA
字号:
/* * @(#)VideoTest.java	1.4 03/02/27 * * Copyright (c) 2000-2003 Sun Microsystems, Inc. All rights reserved.  * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms */package example.mmademo;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import java.util.Vector;/** * An example MIDlet to demo MMAPI features * * @author Sharon.Huang@Eng.sun.com * @version 1.0 */public class VideoTest extends MIDlet implements CommandListener, Runnable {    private static VideoCanvas videoCanvas    = null;    private static VideoPlayer videoPlayer    = null;    private static Vector  videoClips;    private Command               exitCommand = new Command("Exit",                                                    Command.EXIT, 1);    private Command               playCommand = new Command("Play",                                                    Command.ITEM, 1);    //private Command               helpCommand = new Command("Help", Command.HELP, 1);							        //private Alert                 helpScreen  = null;    private Display               display;    private static List           theList;    private static VideoTest      instance = null;    private static Vector urls;    static public VideoTest getInstance() {        return instance;    }    static public List getList() {        return theList;    }    public VideoTest() {        instance = this;        display  = Display.getDisplay(this);        theList  = new List("MMAPI Player", Choice.IMPLICIT);        fillList();        theList.addCommand(playCommand);        theList.addCommand(exitCommand);        theList.setCommandListener(this);    }    private void fillList() {        videoClips = new Vector();        urls = new Vector();        for (int n = 1; n < 100; n++) {            String nthURL = "VideoTest-URL"+ n;            String url = getAppProperty(nthURL);            if (url == null || url.length() == 0) {                break;            }            String nthTitle = "VideoTest-" + n;            String title = getAppProperty(nthTitle);            if (title == null || title.length() == 0) {                title = url;            }            videoClips.addElement(title);            urls.addElement(url);            theList.append(title, null);        }    }        public void startApp() {        display.setCurrent(theList);    }    /**     * Pause is a no-op since there are no background activities or     * record stores that need to be closed.     */    public void pauseApp() {}    /**     * Destroy must cleanup everything not handled by the garbage collector.     */    public synchronized void destroyApp(boolean unconditional) {        if (videoPlayer != null)            videoPlayer.close();        if (videoCanvas != null)            videoCanvas.close();        nullPlayer();    }    public synchronized void nullPlayer() {        videoPlayer = null;        videoCanvas = null;    }    int index = 0;    public void run() {        if (index % 2 == 0) {            videoPlayer = new VideoPlayer(display);            videoPlayer.open((String) urls.elementAt(index));            if (videoPlayer != null) {                display.setCurrent(videoPlayer);                videoPlayer.start();            }        } else {            videoCanvas = new VideoCanvas(display);            videoCanvas.open((String) urls.elementAt(index));            if(videoCanvas != null) {                display.setCurrent(videoCanvas);                videoCanvas.start();            }        }    }    /*     * Respond to commands, including exit     * On the exit command, cleanup and notify that the MIDlet has     * been destroyed.     */    public void commandAction(Command c, Displayable s) {        if (c == exitCommand) {            synchronized (this) {                if (videoPlayer != null || videoCanvas != null) {                     new Thread(new Runnable() {                         public void run() {                            if (videoPlayer != null) {                                videoPlayer.stopVideoPlayer();                                videoPlayer = null;                            } else { //videoCanvas != null                                videoCanvas.stopVideoCanvas();                                videoCanvas = null;                            }                            destroyApp(false);                            notifyDestroyed();                        }                    }).start();                                   } else {                    destroyApp(false);                    notifyDestroyed();                }            }        } else if ((s == theList && c == List.SELECT_COMMAND) || c == playCommand) {            synchronized (this) {                if (videoPlayer != null || videoCanvas != null) {                    return;                }                int i = theList.getSelectedIndex();                index = i;                (new Thread(this)).start();            }        }    }}

⌨️ 快捷键说明

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