import java.io.InputStream;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Item;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class PlayVideo extends MIDlet implements CommandListener {
private Display display;
Form form = new Form("视频播放演示");
Command cmdPlayItem = new Command("通过Item播放", Command.SCREEN, 1);
Command cmdPlayCanvas = new Command("通过Canvas播放", Command.SCREEN, 1);
Command cmdExit = new Command("退出", Command.EXIT, 1);
Player player = null;
public PlayVideo() {
super();
String prop2 = System.getProperty("audio.encodings");
if (prop2 != null) {
System.out.println("照相机支持的图像格式:"+prop2);
}
form.addCommand(cmdPlayItem);
form.addCommand(cmdPlayCanvas);
form.addCommand(cmdExit);
form.setCommandListener(this);
}
protected void startApp() throws MIDletStateChangeException {
display = Display.getDisplay(this);
display.setCurrent(form);
}
protected void pauseApp() {
close();
}
protected void destroyApp(boolean arg0)
throws MIDletStateChangeException {
close();
}
private void playItem() {
try {
InputStream is = getClass().getResourceAsStream("/test.mpg");
player = Manager.createPlayer(is,"Video/mpeg");
player.realize();
//获得视频控制器
VideoControl vc = (VideoControl)player.getControl("VideoControl");
Item item = (Item)vc.initDisplayMode(
VideoControl.USE_GUI_PRIMITIVE, null);
form.append(item);
player.start();
} catch(Exception e) {
e.printStackTrace();
}
}
private void playCanvas() {
try {
InputStream is = getClass().getResourceAsStream("/test.mpg");
player = Manager.createPlayer(is,"Video/mpeg");
player.realize();
MyCanvas mc = new MyCanvas();
//获得视频控制器
VideoControl vc = (VideoControl)player.getControl("VideoControl");
vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, mc);
display.setCurrent(mc);
player.start();
} catch(Exception e) {
e.printStackTrace();
}
}
class MyCanvas extends Canvas {
protected void paint(Graphics p) {
}
}
/**
* 命令按钮事件
*/
public void commandAction(Command c, Displayable s) {
if (c == cmdExit) {
notifyDestroyed();
} else if (c == cmdPlayItem) {
display.setCurrent(form);
new Thread() {
public void run() {
playItem();
}
}.start();
}else if (c == cmdPlayCanvas) {
new Thread() {
public void run() {
playCanvas();
}
}.start();
}
}
private void close() {
if (player != null) {
player.close();
player = null;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
PlayVideo.rar (11个子文件)
PlayVideo
.project 552B
PlayVideo.java 4KB
jmf.log 165B
.settings
org.eclipse.jdt.core.prefs 166B
test.mpg 690KB
deployed
Chap13_MMA_PlayVideo.jar 665KB
Chap13_MMA_PlayVideo.jad 276B
verified
libs
classes
test.mpg 690KB
.eclipseme 233B
.classpath 226B
Chap13_MMA_PlayVideo.jad 251B
共 11 条
- 1
资源评论
penganfeng
- 粉丝: 0
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功