📄 qdvideotest.java
字号:
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
/**
* An example MIDlet to demo MMAPI video features
*
*/
public class QDVideoTest extends MIDlet implements CommandListener, Runnable {
private static QDVideoTest instance = null;
private Command exitCommand = new Command("Exit", Command.EXIT, 1);
private Command playCommand = new Command("Play", Command.ITEM, 1);
private Display display;
private static List theList;
private static QDVideoPlayer videoPlayer = null;
public QDVideoTest() {
// TODO Auto-generated constructor stub
instance = this;
display = Display.getDisplay(this);
theList = new List("MobileVideoIP Player", Choice.IMPLICIT);
theList.addCommand(playCommand);
theList.addCommand(exitCommand);
theList.setCommandListener(this);
display.setCurrent(theList);
}
/*
* 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) {
new ExitThread().start();
} else {
destroyApp(false);
notifyDestroyed();
}
}
} else if ((s == theList && c == List.SELECT_COMMAND)
|| c == playCommand) {
synchronized (this) {
if (videoPlayer != null) {
// return if something is active
// this section is for starting
return;
}
// need to start the players in a separate thread to
// not block the command listener thread during
// Player.realize: if it requires a security
// dialog (like "is it OK to use airtime?"),
// it would block the VM
(new Thread(this)).start();
}
}
}
public void run() {
System.out.println("QDVideoTest:run()");
videoPlayer = new QDVideoPlayer(display);
videoPlayer.open("capture://video");
if (videoPlayer != null) {
display.setCurrent(videoPlayer);
videoPlayer.start();
}
}
/**
* Destroy must cleanup everything not handled
* by the garbage collector.
*/
public synchronized void destroyApp(boolean unconditional) {
if (videoPlayer != null) {
videoPlayer.close();
}
videoPlayer = null;
}
/**
* Called when this MIDlet is paused. If there is currently a Form or Canvas
* displaying video, call its startApp() method.
*/
protected void pauseApp() {
// TODO Auto-generated method stub
if (videoPlayer != null)
videoPlayer.pauseApp();
}
/**
* Called when this MIDlet is started for the first time, or when it returns
* from paused mode. If there is currently a Form or Canvas displaying
* video, call its startApp() method.
*/
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
if (videoPlayer != null)
videoPlayer.startApp();
}
static public QDVideoTest getInstance() {
return instance;
}
static public List getList() {
return theList;
}
class ExitThread extends Thread {
public void run() {
// try {
// this is stop()+deallocate(), but not close(),
// which is done in destroyApp() ...
if (videoPlayer != null) {
videoPlayer.stopVideoPlayer();
}
destroyApp(false);
notifyDestroyed();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -