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());
}

Reply With Quote


