Java Me video player realize error with http - MediaException

1.2k views Asked by At

I'm using the below code (references from, http://www.java-tips.org/java-me-tips/midp/playing-video-on-j2me-devices.html). It fails at 'realize()', with the javax.microedition.media.MediaException, "Unable to create native player". What is the problem here?
I tried this using both Eclipse and Netbeans. Am I missing some "internet" permissions or using any incorrect encoding, the video is an external 'mpg' test-resource and does work fine when downloaded through a desktop browser.

public void run()
{
    String url = "http://www.fileformat.info/format/mpeg/sample/05e7e78068f44f0ea748855ef33c9f4a/MELT.MPG";

    //Append the GUI to a form
    Form form = new Form("Video on java mobile!");
    Display display = Display.getDisplay(this);
    display.setCurrent(form);

    try
    {
        HttpConnection conn = (HttpConnection)Connector.open(url, 
            Connector.READ_WRITE);
        InputStream is = conn.openInputStream();

        Player p = Manager.createPlayer(is,"video/mpeg");
        //I tried the below, but that didn't work either
        //Player p = Manager.createPlayer(url);
        p.realize();

        //Get the video controller
        VideoControl video = (VideoControl) p.getControl("VideoControl");
        if(video != null) 
        {
            //Get a GUI to display the video
            Item videoItem = (Item)video.initDisplayMode(
            VideoControl.USE_GUI_PRIMITIVE, null);

            form.append(videoItem);
        }

        //Start the video          
        p.prefetch();
        p.start();
    }
    catch(Exception e)
    {
        form.append(url + " Error:" + e.getMessage());
    }

}

I've just started with Java, Eclipse, Netbeans. Since, there similar samples found everywhere, I believe I'm missing something very basic. Can someone please help?

1

There are 1 answers

0
Karuna Sorate On BEST ANSWER

The problem here was the video file. Although my source video seemed "mpeg", it wasn't acceptable to the emulator. After searching through a bit, I found a converter and I manually converted some sample mp4 to "mpeg". It finally worked with the same emulator, after I tried to download and play these manually converted files.

One piece of advise if you are new J2ME/JavaME apps (like me), keep playing with the input data sources/formats and the emulators. Switching emulators or the input data-formats is an easy way to identify the not-so-evident problems.