Java
--
Questions
--
Followers
Top Experts
Video Player in J2Me Mobile Device
Hello Experts,
I hope you are all fine and doing well..
I am in a big trouble here and need some assistance from your side.
I am developing a J2Me mobile app in which I have to play videos from Amazon Cloud Signed Url. I have gone through all the internet resources and tested them but no one is working for me at all. Infact I am not even able to play normal video (mp4,3gp) urls also. I am not sure what I am missing the code. I am pasting my code below.
Question: 1. What format can a J2Me player play.
2. Is it possible at all to play signed url or not.
3. Can I stream using Amazon signed/unsigned url on J2Me device.
Please provide me working sample code if possible. I have tried all internet resources they don't work at all on the phones. The only code which works on simulator is the one with mpg file... but that doesn't work on the phone.
Here is the code. This one plays mpg video on simulator but not on phone. But i need to play mp4 or 3gp or flv
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import javax.microedition.lcdui.* ;
import javax.microedition.media.* ;
import javax.microedition.media.c ontrol.*;
import javax.microedition.midlet. *;
public class YesVideo extends MIDlet implements
    CommandListener, PlayerListener, Runnable {
  private Display display;
  private Form form;
  private TextField url;
  private Command start = new Command("Play",
      Command.SCREEN, 1);
  private Command stop = new Command("Stop",
      Command.SCREEN, 2);
  private Player player;
  public YesVideo() {
    display = Display.getDisplay(this);
    form = new Form("YesNet Video Player");
    url = new TextField("Enter URL:", "http://java.sun.com/products/java-media/mma/media/test-mpeg.mpg", 100, TextField.URL);
    form.append(url);
    form.addCommand(start);
    form.addCommand(stop);
    form.setCommandListener(th is);
    display.setCurrent(form);
  }
  protected void startApp() {
    try {
      if (player != null && player.getState()
          == Player.PREFETCHED) {
        player.start();
      } else {
        defplayer();
        display.setCurrent(form);
      }
    } catch (MediaException me) {
      reset();
    }
  }
  protected void pauseApp() {
    try {
      if (player != null && player.getState()
          == Player.STARTED) {
        player.stop();
      } else {
        defplayer();
      }
    } catch (MediaException me) {
      reset();
    }
  }
  protected void destroyApp(
      boolean unconditional) {
    form = null;
    try {
      defplayer();
    } catch (MediaException me) {
    }
  }
  public void playerUpdate(Player player,
      String event, Object data) {
    if (event == PlayerListener.END_OF_MEDI A) {
      try {
        defplayer();
      } catch (MediaException me) {
      }
      reset();
    }
  }
  public void commandAction(Command c, Displayable d) {
    if (c == start) {
      start();
    } else if (c == stop) {
      stopPlayer();
    }
  }
  public void start() {
    Thread t = new Thread(this);
    t.start();
  }
// to prevent blocking, all communication should
// be in a thread
// and not in commandAction
  public void run() {
    play(getURL());
  }
  String getURL() {
    return url.getString();
  }
  void play(String url) {
    try {
      VideoControl vc;
      defplayer();
// create a player instance
      player = Manager.createPlayer(url);
      player.addPlayerListener(t his);
// realize the player
      player.realize();
      vc = (VideoControl) player.getControl(
          "VideoControl");
      if (vc != null) {
        Item video = (Item) vc.initDisplayMode(
            vc.USE_GUI_PRIMITIVE, null);
        Form v = new Form("Playing Video...");
        StringItem si = new StringItem("Status: ",
            "Playing...");
        v.append(si);
        v.append(video);
        display.setCurrent(v);
      }
      player.prefetch();
      player.start();
    } catch (Throwable t) {
      //reset();
      throw new RuntimeException(t.getMess age());
    }
  }
  void defplayer() throws MediaException {
    if (player != null) {
      if (player.getState() == Player.STARTED) {
        player.stop();
      }
      if (player.getState() == Player.PREFETCHED) {
        player.deallocate();
      }
      if (player.getState() == Player.REALIZED
          || player.getState() == Player.UNREALIZED) {
        player.close();
      }
    }
    player = null;
  }
  void reset() {
    player = null;
  }
  void stopPlayer() {
    try {
      defplayer();
    } catch (MediaException me) {
      throw new RuntimeException(me.getMes sage());
    }
    reset();
  }
}
Thanks,
Amarjit
I hope you are all fine and doing well..
I am in a big trouble here and need some assistance from your side.
I am developing a J2Me mobile app in which I have to play videos from Amazon Cloud Signed Url. I have gone through all the internet resources and tested them but no one is working for me at all. Infact I am not even able to play normal video (mp4,3gp) urls also. I am not sure what I am missing the code. I am pasting my code below.
Question: 1. What format can a J2Me player play.
2. Is it possible at all to play signed url or not.
3. Can I stream using Amazon signed/unsigned url on J2Me device.
Please provide me working sample code if possible. I have tried all internet resources they don't work at all on the phones. The only code which works on simulator is the one with mpg file... but that doesn't work on the phone.
Here is the code. This one plays mpg video on simulator but not on phone. But i need to play mp4 or 3gp or flv
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import javax.microedition.lcdui.*
import javax.microedition.media.*
import javax.microedition.media.c
import javax.microedition.midlet.
public class YesVideo extends MIDlet implements
    CommandListener, PlayerListener, Runnable {
  private Display display;
  private Form form;
  private TextField url;
  private Command start = new Command("Play",
      Command.SCREEN, 1);
  private Command stop = new Command("Stop",
      Command.SCREEN, 2);
  private Player player;
  public YesVideo() {
    display = Display.getDisplay(this);
    form = new Form("YesNet Video Player");
    url = new TextField("Enter URL:", "http://java.sun.com/products/java-media/mma/media/test-mpeg.mpg", 100, TextField.URL);
    form.append(url);
    form.addCommand(start);
    form.addCommand(stop);
    form.setCommandListener(th
    display.setCurrent(form);
  }
  protected void startApp() {
    try {
      if (player != null && player.getState()
          == Player.PREFETCHED) {
        player.start();
      } else {
        defplayer();
        display.setCurrent(form);
      }
    } catch (MediaException me) {
      reset();
    }
  }
  protected void pauseApp() {
    try {
      if (player != null && player.getState()
          == Player.STARTED) {
        player.stop();
      } else {
        defplayer();
      }
    } catch (MediaException me) {
      reset();
    }
  }
  protected void destroyApp(
      boolean unconditional) {
    form = null;
    try {
      defplayer();
    } catch (MediaException me) {
    }
  }
  public void playerUpdate(Player player,
      String event, Object data) {
    if (event == PlayerListener.END_OF_MEDI
      try {
        defplayer();
      } catch (MediaException me) {
      }
      reset();
    }
  }
  public void commandAction(Command c, Displayable d) {
    if (c == start) {
      start();
    } else if (c == stop) {
      stopPlayer();
    }
  }
  public void start() {
    Thread t = new Thread(this);
    t.start();
  }
// to prevent blocking, all communication should
// be in a thread
// and not in commandAction
  public void run() {
    play(getURL());
  }
  String getURL() {
    return url.getString();
  }
  void play(String url) {
    try {
      VideoControl vc;
      defplayer();
// create a player instance
      player = Manager.createPlayer(url);
      player.addPlayerListener(t
// realize the player
      player.realize();
      vc = (VideoControl) player.getControl(
          "VideoControl");
      if (vc != null) {
        Item video = (Item) vc.initDisplayMode(
            vc.USE_GUI_PRIMITIVE, null);
        Form v = new Form("Playing Video...");
        StringItem si = new StringItem("Status: ",
            "Playing...");
        v.append(si);
        v.append(video);
        display.setCurrent(v);
      }
      player.prefetch();
      player.start();
    } catch (Throwable t) {
      //reset();
      throw new RuntimeException(t.getMess
    }
  }
  void defplayer() throws MediaException {
    if (player != null) {
      if (player.getState() == Player.STARTED) {
        player.stop();
      }
      if (player.getState() == Player.PREFETCHED) {
        player.deallocate();
      }
      if (player.getState() == Player.REALIZED
          || player.getState() == Player.UNREALIZED) {
        player.close();
      }
    }
    player = null;
  }
  void reset() {
    player = null;
  }
  void stopPlayer() {
    try {
      defplayer();
    } catch (MediaException me) {
      throw new RuntimeException(me.getMes
    }
    reset();
  }
}
Thanks,
Amarjit
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
ASKER CERTIFIED SOLUTION
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Thanks ,..
Let me try streaming method now.
Let me try streaming method now.
Hi girionis,
I tried the stream method. It tries to play the video but then the app quits with Message: java error.
I tried the stream method. It tries to play the video but then the app quits with Message: java error.
Hi Girionis,
I tried https url for playing but it says "Certificate was issued by an unrecognized entity"
I tried https url for playing but it says "Certificate was issued by an unrecognized entity"






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
You probably need to sign the midlet. Have a look here for possible solutions:
http://stackoverflow.com/questions/4666487/certificate-was-issued-by-an-unrecognized-entity
http://www.developer.nokia.com/Community/Discussion/showthread.php?108170-Certificate-was-issued-by-an-unrecognized-Entity
http://stackoverflow.com/questions/4666487/certificate-was-issued-by-an-unrecognized-entity
http://www.developer.nokia.com/Community/Discussion/showthread.php?108170-Certificate-was-issued-by-an-unrecognized-Entity
When i try to sign midlet with the certificate i got from the https url. I asks me for unlcok password. But i don't have any password for it. I asked IT team in but they don't have any.
Java
--
Questions
--
Followers
Top Experts
Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.