×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    3

    Problems with streaming a video File using J2me

    Hi
    I have written this code to play a video file from the server but its giving me null pointer exception whenever I am trying to create a video Control,can some one point out the glitch in my code .


    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;

    import java.util.Vector;
    /*import javax.microedition.io.Connector;
    import javax.microedition.io.Connector;
    import javax.microedition.io.file.FileConnection;
    import javax.microedition.rms.RecordStore;*/

    import javax.microedition.*;
    import java.io.InputStreamReader;
    //import javax.microedition.io.StreamConnection;
    import javax.microedition.lcdui.Image;
    //import java.io.DataInputStream;
    import javax.microedition.lcdui.ImageItem;
    import javax.microedition.lcdui.ItemCommandListener;
    import javax.microedition.media.Player;
    import javax.microedition.media.control.VideoControl;
    import javax.microedition.io.Connector;
    //import java.io.OutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    //import javax.microedition.io.StreamConnection;
    import javax.microedition.io.HttpConnection;
    import java.io.DataInputStream;
    import java.io.ByteArrayInputStream;
    import javax.microedition.media.Manager;
    import java.io.ByteArrayOutputStream;

    import javax.microedition.media.MediaException;
    import javax.microedition.media.control.GUIControl;
    import javax.microedition.media.control.RecordControl;



    // This is the part of the code where iam trying to play the video file from the server


    Player player;
    GUIControl guiControl = null;


    try
    {
    //Create a new Player pointing to the video file.
    //This can use any valid URL.

    // url -> points to the 3gp file in the server

    HttpConnection connection = (HttpConnection) Connector.open(url);

    DataInputStream dataIn = connection.openDataInputStream();

    //byte[] buffer = new byte[1000];
    byte[] buffer = new byte[1024];
    int read = -1;
    int lk = 0;

    // Read the content from url.
    ByteArrayOutputStream byteout = new ByteArrayOutputStream();

    while ((read=dataIn.read(buffer))>=0)
    {
    lk++;
    byteout.write(buffer, 0, read);
    }

    dataIn.close();
    connection.close();

    // Fill InputStream to return with content read from the URL.
    ByteArrayInputStream byteIn =
    new ByteArrayInputStream(byteout.toByteArray());

    HttpConnection conn = (HttpConnection) Connector.open(url, Connector.READ_WRITE);


    System.out.println("asdasdasdasdasdasdasdasdasdasdasdasdsad");
    player = Manager.createPlayer(byteIn, "video/3GPP");

    try
    {
    player.start();
    player.getControls();

    }
    catch (Exception ex)
    {
    System.out.println("Exception: " + ex.toString());
    }
    player.realize();
    //Create a new VideoControl.
    videoControl = (VideoControl)player.getControl("VideoControl");
    //Initialize the video mode using a Field.
    videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null);

    //Set the video control to be visible.
    videoControl.setVisible(true);


    }
    catch (Exception ex)
    {
    System.out.println(ex.toString());
    }

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: Problems with streaming a video File using J2me

    What is your target device? which streaming server your are connecting to ?

    thanks,
    ~Amitabh
    Follow me on my blog for Innovative Mobile Apps

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    3

    Re: Problems with streaming a video File using J2me

    Target Device is Nokia E -61 and no specific server

  4. #4
    Nokia Developer Champion
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: Problems with streaming a video File using J2me

    try this portion of code in ur code

    Code:
    player = Manager.createPlayer(byteIn, "video/3gpp");
    
    try
    {
    
    //Create a new VideoControl.
    videoControl = (VideoControl)player.getControl("VideoControl");
    //Initialize the video mode using a Field.
    videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null);
    
    //Set the video control to be visible.
    videoControl.setVisible(true);
    
    
    
    }
    catch (Exception ex)
    {
    System.out.println("Exception: " + ex.toString());
    }
    player.realize();
    player.start();

    The format use for 3gp file is : "video/3gpp" ;
    Always get the contro before realizilng and start the player..


    check and reply...
    thanks,
    jitu_goldie..

    KEEP TRYING..

  5. #5
    Registered User
    Join Date
    Oct 2009
    Posts
    34

    Re: Problems with streaming a video File using J2me

    HI
    there is a good example in Wtk2.5 apps so please take help from there.Still if you confusing then we will help you.But Take help from there which is good example
    dont lose hope

Similar Threads

  1. Selection of wireless toolkit for video streaming in j2me
    By ziathegreat in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2009-06-11, 08:02
  2. Contacts fields order??
    By timatima in forum Symbian
    Replies: 1
    Last Post: 2007-06-08, 13:51
  3. Streaming video + J2ME application interruptions
    By redlex in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-11-27, 11: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
  •