basically im having null pointer exception
//read an inputstream
is = new DataInputStream(new FileInputStream("test.mpg"));
loadBytes(is);
//pass it as a datasource for the player
public void loadBytes(InputStream is){
DataSource ds=new DataSource(is);
player = Manager.createPlayer(ds);
//datasource class
import java.io.*;
import java.nio.ByteBuffer;
import javax.media.*;
import javax.media.protocol.*;
public class DataSource extends PullDataSource {
private InputStream is;
private byte [] bytes;
/** Creates new MediaViewerDataSource */
public DataSource(InputStream is) {
super();
this.is = is;
try{
int byteCount = is.available();
bytes = new byte [byteCount];
is.read(bytes);
}
catch (Exception e){
System.out.println(e);
}
}
public PullSourceStream [] getStreams() {
PullSourceStream [] streams = new PullSourceStream [1];
InputSourceStream iss = new InputSourceStream(new ByteArrayInputStream(bytes), new FileTypeDescriptor(ContentDescriptor.RAW));
streams[0] = iss;
return streams;
}
public void connect() {}
public void disconnect() {}
public String getContentType() {
return new String(FileTypeDescriptor.MPEG);
}
public MediaLocator getLocator() {
return null;
}
public void initCheck() {}
public void setLocator(MediaLocator source) {}
public void start() {}
public void stop() {}
public Object getControl(String s){
return null;
}
public Object [] getControls(){
return null;
}
public Time getDuration(){
return null;
}
}
//inputsourcestream class
import java.io.InputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import javax.media.protocol.ContentDescriptor;
import javax.media.protocol.PullSourceStream;
import javax.media.protocol.Seekable;
import javax.media.protocol.SourceStream;
/**
* Build a source stream out of an input stream.
*
* @see DataSource
* @see SourceStream
* @see java.io.InputStream
*
* @version %I%, %E%.
*
*/
public
class InputSourceStream implements PullSourceStream, Seekable {
protected InputStream stream;
protected boolean eosReached;
ContentDescriptor contentType;
protected ByteBuffer inputBuffer;
/**
* Construct an <CODE>InputSourceStream</CODE> from an input stream.
*
* @param s The input stream to build the source stream from.
* @param type The content-type of the source stream.
*/
public InputSourceStream(InputStream s, ContentDescriptor type) {
stream = s;
eosReached = false;
contentType = type;
}
/**
* Get the content type for this stream.
*
* @return content descriptor for the stream.
*/
public ContentDescriptor getContentDescriptor() {
return contentType;
}
/**
* Obtain the content length
*
* @return content length for this stream.
*/
public long getContentLength() {
return SourceStream.LENGTH_UNKNOWN;
}
/**
* Query if the next read will block.
*
* @return true if a read will block.
*/
public boolean willReadBlock() {
if( eosReached == true) {
return true;
} else {
try {
return stream.available() == 0;
} catch (IOException e) {
return true;
}
}
}
/**
* Read a buffer of data.
*
* @param buffer The buffer to read data into.
* @param offset The offset into the buffer for reading.
* @param length The number of bytes to read.
* @return The number of bytes read or -1 indicating end-of-stream.
*/
//this where the problem lies
//unable to read the stream into the
// inputBuffer thus giving me the error
public int read(byte[] buffer, int offset, int length) throws IOException { int bytesRead = stream.read(buffer, offset, length); if( bytesRead == -1) { eosReached = true;
}
inputBuffer.get(buffer,offset,length);
return bytesRead;
}
/**
* Turn the stream off.
*
* @exception IOException Thrown if there is a problem closing the stream.
*/
public void close() throws IOException {
stream.close();
}
/**
* Return if the end of stream has been reached.
* @return true if the end of the stream has been reached.
*/
// $jdr: This is a bug. Need to figure out
// the "correct" way to determine, before a read
// is done, if we're at EOS.
public boolean endOfStream() {
return eosReached;
}
/**
* Returns an zero length array because no controls
* are supported.
*
* @return a zero length <code>Object</code> array.
*/
public Object[] getControls() {
return new Object[0];
}
/**
* Returns <code>null</code> because no controls are implemented.
*
* @return <code>null</code>.
*/
public Object getControl(String controlName) {
return null;
}
public long seek(long where) {
try {
inputBuffer.position((int)(where));
return where;
}
catch (IllegalArgumentException E) {
return this.tell(); // staying at the current position
}
}
public long tell() {
return inputBuffer.position();
}
public void SeekableStream(ByteBuffer byteBuffer) {
inputBuffer = byteBuffer;
this.seek((long)(0)); // set the ByteBuffer to to beginning
}
public boolean isRandomAccess() {
// TODO Auto-generated method stub
return false;
}
}
please take a look and i'll appreciate any assistance
thank you