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

📄 playvediodemo.java

📁 人民邮电出版社的《J2ME手机开发入门》全部源代码
💻 JAVA
字号:
/*
 * PlayVedioDemo.java
 *
 * Created on 2005年5月2日, 上午1:43
 */

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

import javax.microedition.media.*;
import javax.microedition.media.control.*;
/**
 *
 * @author  Liu Bin
 * @version
 */
public class PlayVedioDemo extends MIDlet implements CommandListener {
    private Display display;
    //命令按钮
    private Command cmdPlay = new Command("播放", Command.OK, 1);
    private Command cmdExit = new Command("退出", Command.STOP, 1);
    Form form = new Form("视频播放演示");
    Player videoPlayer;
    
    public PlayVedioDemo() {
        form.addCommand(cmdPlay);
        form.addCommand(cmdExit);
        form.setCommandListener(this);
    }
    
    public void startApp() {
        display = Display.getDisplay(this);
        display.setCurrent(form);
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
    
    /**
     * 命令按钮事件
     */
    public void commandAction(Command c, Displayable s) {
        if (c == cmdExit) {
            videoPlayer.close();
            videoPlayer = null;
            this.notifyDestroyed();
        }
        
        if (c == cmdPlay) {
            try {
                java.io.InputStream is = getClass().getResourceAsStream("/1.mpg");
                System.out.println("已经装载Mpeg文件");
                
                videoPlayer = Manager.createPlayer(is,"Video/mpeg");
                System.out.println("已经创建Player对象");
                
                videoPlayer.realize();
                
                //获得视频控制器
                VideoControl vc = (VideoControl)videoPlayer.getControl("VideoControl");
                Item videoItem = (Item)vc.initDisplayMode(
                        VideoControl.USE_GUI_PRIMITIVE, null);
                form.append(videoItem);
                videoPlayer.start();
            } catch(Exception e) {
                System.out.println("播放视频异常:" + e.toString());
            }
        }
    }
}

⌨️ 快捷键说明

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