最近在研究流媒体在J2ME上的实现,
有个方案是用两个player一个播数据,一个拿数据,不断的交换角色
有人说这个实现的缺陷是不能同时存在两个player 所以写了个测试用例
发觉在NOKIA 6300上面,只要不是两个player都start(),即使调用了prefetch也是没有关系的。
但在nokia 6303上面,两个player不能同时处于prefetch状态的。
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.media.Player;
import javax.microedition.media.Manager;
import javax.microedition.media.*;
import java.io.*;
import javax.microedition.media.control.VideoControl;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Display;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2010</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class TwoPlayerDemo extends MIDlet implements CommandListener {
public void commandAction(Command command, Displayable displayable) {
if(command== exit)
{
try {
destroyApp(false);
notifyDestroyed();
} catch (MIDletStateChangeException ex) {
}
}
}
private VideoCanvas videoCanvas;
private Command exit;
public TwoPlayerDemo() {
exit = new Command("Exit", Command.SCREEN, 1);
}
/**
* destroyApp
*
* @param _boolean boolean
* @throws MIDletStateChangeException
* @todo Implement this javax.microedition.midlet.MIDlet method
*/
protected void destroyApp(boolean _boolean) throws
MIDletStateChangeException {
}
/**
* pauseApp
*
* @todo Implement this javax.microedition.midlet.MIDlet method
*/
protected void pauseApp() {
}
/**
* startApp
*
* @throws MIDletStateChangeException
* @todo Implement this javax.microedition.midlet.MIDlet method
*/
protected void startApp() throws MIDletStateChangeException {
try {
Player play1 = Manager.createPlayer(getClass().getResourceAsStream("/3gp.jpg"), "video/3gpp");
play1.realize();
play1.prefetch();
VideoControl videoControl = (VideoControl) play1.getControl(
"VideoControl");
videoCanvas = null;
if (videoControl != null) {
videoCanvas = new VideoCanvas(this, videoControl);
videoCanvas.addCommand(exit);
videoCanvas.setCommandListener(this);
Display.getDisplay(this).setCurrent(videoCanvas);
play1.start();
} else
play1.start();
Player play2 = Manager.createPlayer(getClass().getResourceAsStream(
"/3gp.jpg"), "video/3gpp");
play2.realize();
play2.prefetch();
// play2.start();
} catch (MediaException ex) {
} catch (IOException ex) {
}
}
}