Error at Motorola v3x
HELP!!!
I installed a J2ME application on my Motorola v3x.
when i run the application i get the following error:
"Cannot create player"
The code seems to be OK, I checked it on some Sony Ericsson emulators. I didn't find a suitable emulators for my motorola device.
Here is the code:
package videoPlayer;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/** A simple video player MIDlet using JSR 135 - Mobile Media API */
public class VideoPlayer extends MIDlet implements CommandListener
{
private Command exitCommand;
private Command playCommand;
private Command contentTypeCommand;
private Display display;
private TextField textField;
public Form form;
private Gauge gauge;
private static final int GAUGE_LEVELS = 4;
private static final int GAUGE_MAX = 12;
private static final String DEFAULT_URL = "http://localhost/test.mpg";
public VideoPlayer() {
display = Display.getDisplay(this);
form = new Form("Video Player");
textField = new TextField("Video URL", DEFAULT_URL, 100, TextField.ANY);
gauge = new Gauge("Acquiring video", false, GAUGE_MAX, 0);
exitCommand = new Command("Exit", Command.EXIT, 2);
playCommand = new Command("Play", Command.SCREEN, 1);
contentTypeCommand = new Command("Supported media types", Command.SCREEN, 2);
form.addCommand(playCommand);
form.addCommand(exitCommand);
form.addCommand(contentTypeCommand);
form.setCommandListener(this);
form.append(textField);
}
public void startApp(){
display.setCurrent(form);
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
}
public void commandAction(Command c, Displayable s){
if(c == exitCommand){
destroyApp(false);
notifyDestroyed();
}
else if(c == playCommand){
gauge.setValue(0);
form.append(gauge);
VideoCanvas videoCanvas = new VideoCanvas(this);
videoCanvas.initializeVideo(textField.getString());
}
else if (c == contentTypeCommand){
String url = textField.getString();
int position = url.indexOf(':');
String protocol = url.substring(0, position);
SupportedTypes typesUI = new SupportedTypes(this, protocol);
display.setCurrent(typesUI);
}
}
public void updateGauge(){
int current = gauge.getValue();
current = (current + GAUGE_MAX/GAUGE_LEVELS);
gauge.setValue(current);
}
}
package videoPlayer;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import java.io.*;
/** Acquires the video content and renders it */
public class VideoCanvas extends Canvas implements CommandListener, PlayerListener, Runnable {
private VideoPlayer parent;
private Display display;
private Player player;
private VideoControl videoControl;
private String url;
private Thread initializer;
private Command close;
private Command rePlay;
public VideoCanvas(VideoPlayer parent){
super();
this.parent = parent;
display = Display.getDisplay(parent);
close = new Command("close", Command.SCREEN, 1);
addCommand(close);
setCommandListener(this);
}
public void initializeVideo(String url){
this.url = url;
initializer = new Thread(this);
initializer.start();
}
public void run(){
try {
player = Manager.createPlayer(url);
parent.updateGauge();
player.addPlayerListener(this);
player.realize();
parent.updateGauge();
player.prefetch();
parent.updateGauge();
} catch (IOException ioe) {
Alert alert = new Alert("IOException thrown", ioe.getMessage(), null, AlertType.ERROR);
display.setCurrent(alert);
} catch (MediaException me) {
Alert alert = new Alert("MediaException thrown", me.getMessage(), null, AlertType.ERROR);
display.setCurrent(alert);
}
playVideo();
}
public void playVideo(){
try {
// Get the video control and set it to the current display.
videoControl = (VideoControl)player.getControl("VideoControl");
if (videoControl != null) {
videoControl.initDisplayMode(videoControl.USE_DIRECT_VIDEO, this);
}
parent.updateGauge();
int cHeight = this.getHeight();
int cWidth = this.getWidth();
videoControl.setDisplaySize(cWidth, cHeight);
display.setCurrent(this);
videoControl.setVisible(true);
player.start();
} catch (MediaException me) {
Alert alert = new Alert("MediaException thrown", me.getMessage(), null, AlertType.ERROR);
display.setCurrent(alert);
}
}
/** Paints background color */
public void paint(Graphics g){
g.setColor(128, 128, 128);
g.fillRect(0, 0, getWidth(), getHeight());
}
public void playerUpdate(Player p, String event, Object eventData) {
//add "Replay" option when video is finished
if (event == PlayerListener.END_OF_MEDIA)
{
if (rePlay == null)
{
rePlay = new Command("re-play", Command.SCREEN, 1);
addCommand(rePlay);
}
}
}
public void commandAction(Command c, Displayable s) {
if(c == rePlay){
try{
player.start();
} catch (MediaException me) {
Alert alert = new Alert("MediaException thrown", me.getMessage(), null, AlertType.ERROR);
display.setCurrent(alert);
}
}
else if(c == close){
player.close();
parent.form.delete(1);
display.setCurrent(parent.form);
url=null;
parent=null;
}
}
}

