×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    3

    Embedding video in an application

    Hi, I'm trying to embed a video in a J2ME application. I'm doing test with SUN's sample video for mobile test-mpeg.mpg. I've been testing playing in my N80, in SUN's emulator and Nokia emulator and doesn't work. Here is some code from my MIDLet:

    videoPlayer = Manager.createPlayer( getClass().getResourceAsStream("/com/mypackage/media/testmpeg.3gp"),
    "video/3gpp" );

    videoPlayer.addPlayerListener(this);

    videoPlayer.realize();

    VideoControl vc = (VideoControl) getVideoPlayer().getControl("VideoControl");

    Display.getDisplay(this).setCurrent( getVideoCanvas() );

    //Get a GUI to display the video
    Item videoItem = (Item) vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, getVideoCanvas());

    videoPlayer.start();

    Where, getVideoCanvas() return a Canvas. I've test with mpeg, 3gp and mp4 and doesn't work in any case. Am I doing something wrong?

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Embedding video in an application

    Is the path "/com/mypackage/media/testmpeg.3gp" correct? Also, which Exception (if any) does you code throw?

    Pit

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    3

    Re: Embedding video in an application

    This is the error log in Eclipse:

    MIDlet: HomeMidlet
    JVMJNCK038E JNI error in FromReflectedMethod: Argument #2 (0x3C61EDFC) is not a valid object reference. It's type is: unknown

    JVMJNCK080E Error detected in the outermost frame of an attached thread

    JVMJNCK023E JNI error detected. Continuing...

    And this is the complete source code:

    public void playVideo() {
    try{
    getVideoPlayer().realize();

    VideoControl vc = (VideoControl) getVideoPlayer().getControl("VideoControl");

    switchDisplayable(null, getVideoCanvas());

    //Get a GUI to display the video
    Item videoItem = (Item) vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, getVideoCanvas());

    videoPlayer.start();
    }catch(Exception e){
    Alert alert = new Alert("ERROR");

    if(e.getClass() == MediaException.class)
    alert.setString("No se puede reproducir el vídeo.");

    if(e.getClass() == NullPointerException.class)
    alert.setString("No se pudo cargar el video");

    e.printStackTrace();

    switchDisplayable(alert, getSelectionScreenFrm());
    }
    }

    public Player getVideoPlayer() {
    if(videoPlayer==null){
    try{
    videoPlayer = Manager.createPlayer( getClass().getResourceAsStream(VIDEO_LOCATION),VIDEO_TYPE );
    videoPlayer.addPlayerListener(this);
    }catch(Exception e){
    Alert alert = new Alert("ERROR");

    if(e.getClass() == IOException.class)
    alert.setString("No se ha encontrado el video.");

    if(e.getClass() == MediaException.class)
    alert.setString("No se puede reproducir el video.");

    e.printStackTrace();

    }
    }
    return videoPlayer;
    }

    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
    Display display = getDisplay();
    if (alert == null) {
    display.setCurrent(nextDisplayable);
    } else {
    display.setCurrent(alert, nextDisplayable);
    }
    }

    I've tried playing mpeg, 3gp and mp4 and no one works in the emulator neither in my nokia N80 device. Maybe the bug is in the Canvas implementation? This is my canvas:

    public class VideoCanvas extends Canvas implements CommandListener {
    /**
    * constructor
    */
    public VideoCanvas() {
    try {
    // Set up this canvas to listen to command events
    setCommandListener(this);
    // Add the Exit command
    addCommand(new Command("Exit", Command.EXIT, 1));
    } catch(Exception e) {
    e.printStackTrace();
    }
    }

    /**
    * paint
    */
    public void paint(Graphics g) {
    }

    /**
    * Called when a key is pressed.
    */
    protected void keyPressed(int keyCode) {
    }

    /**
    * Called when a key is released.
    */
    protected void keyReleased(int keyCode) {
    }

    /**
    * Called when a key is repeated (held down).
    */
    protected void keyRepeated(int keyCode) {
    }

    /**
    * Called when the pointer is dragged.
    */
    protected void pointerDragged(int x, int y) {
    }

    /**
    * Called when the pointer is pressed.
    */
    protected void pointerPressed(int x, int y) {
    }

    /**
    * Called when the pointer is released.
    */
    protected void pointerReleased(int x, int y) {
    }

    /**
    * Called when action should be handled
    */
    public void commandAction(Command command, Displayable displayable) {
    }

    }

  4. #4
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: Embedding video in an application

    As jappit suggested, make sure that the file is located in that directory inside the JAR file (you can open the JAR file with WinZip for example to see the folder structure inside the archive)

    Hartti

  5. #5
    Registered User
    Join Date
    May 2008
    Posts
    3

    Re: Embedding video in an application

    I've discovered the error, I had a line g.drawstring in the paint method. Now my Canvas class looks like this my canvas code:

    public class VideoCanvas extends Canvas {
    /**
    * constructor
    */
    public VideoCanvas() {
    super();
    }

    /**
    * paint
    */
    public void paint(Graphics g) {
    g.setColor(0x00000000); // black
    g.fillRect(0, 0, getWidth(), getHeight());
    }
    }

    Now the video file is being played in the Nokia's emulator but I get this error in eclipse's console view:

    JVMJNCK038E JNI error in FromReflectedMethod: Argument #2 (0x3C61EDFC) is not a valid object reference. It's type is: unknown

    JVMJNCK080E Error detected in the outermost frame of an attached thread

    JVMJNCK023E JNI error detected. Continuing...


    But the video is being played. In the device is not working, the video file isn't loaded.

Similar Threads

  1. Replies: 1
    Last Post: 2006-05-16, 11:33
  2. Video clips from my application.
    By Shaikuny in forum Symbian Media (Closed)
    Replies: 0
    Last Post: 2004-11-25, 16:34
  3. Replies: 2
    Last Post: 2003-06-30, 17:36
  4. Video in Application
    By Teamon in forum Mobile Java General
    Replies: 2
    Last Post: 2003-04-14, 08:52
  5. 3650 video application problem
    By KitsonSiu in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2002-09-18, 16:37

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×