472,363 Members | 1,981 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,363 software developers and data experts.

Problem Converting Byte Array to Datasource For JMF

3
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
Feb 21 '08 #1
2 11443
r035198x
13,262 8TB
1.) Please use code tags when posting code.
2.) Read the exception trace again. Which line in your code is reported for that exception?
Feb 21 '08 #2
shahiz
3
im sorry about not using code tags
was my first post

this is error from the program

Expand|Select|Wrap|Line Numbers
  1. LoadInputStream.loadBytes() - Creating DataSource (InputStream)
  2. LoadInputStream.loadBytes() - Creating Player
  3. LoadInputStream.loadBytes() - Adding Controller Listener
  4. LoadInputStream.loadBytes() - realizing player
  5. Exception in thread "JMF thread: com.sun.media.amovie.AMController@1855af5[ com.
  6. sun.media.amovie.AMController@1855af5 ] ( realizeThread)" java.lang.NullPointerException
  7.         at InputSourceStream.tell(InputSourceStream.java:146)
  8.         at com.sun.media.amovie.AMController.seek(AMController.java:361)
  9.         at com.sun.media.amovie.ActiveMovie.seek(ActiveMovie.java:279)
  10.         at com.sun.media.amovie.ActiveMovie.<init>(ActiveMovie.java:66)
  11.         at com.sun.media.amovie.AMController.createActiveMovie(AMController.java:324)
  12.         at com.sun.media.amovie.AMController.doRealize(AMController.java:416)
  13.         at com.sun.media.RealizeWorkThread.process(BasicController.java:1400)
  14.         at com.sun.media.StateTransitionWorkThread.run(BasicController.java:1339
it seem that the read method in InputSourceStream class does not read the stream
Expand|Select|Wrap|Line Numbers
  1. public int read(byte[] buffer, int offset, int length) throws IOException {    
  2. int bytesRead = stream.read(buffer, offset, length);
  3. if( bytesRead == -1) {
  4. eosReached = true;
  5. }
  6. inputBuffer.get(buffer,offset,length);
  7. return bytesRead;
  8. }
this is the null pointer exception error
Expand|Select|Wrap|Line Numbers
  1. public long tell() {
  2. return inputBuffer.position();
  3. }
Feb 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: matt melton | last post by:
Hi there, I am trying to write a method that accepts an array of any primitive type and will return the same array without copying memory as an array of bytes. ie. I'd like to be able to do...
5
by: c duden | last post by:
I am attempting to encrypt some text and be able to decrypt it at a later time. I have two methods to do this: public static Byte EncryptText(string textToEncrypt, string encryptionHash) {...
2
by: Govind | last post by:
Hi All, I want to Convert 32 bit integers to byte in right alighed format . For 32 = the usual way is BitConverter.GetBytes(int32)==> xx xx 00 00 , but i want right aligned like 00 00 xx xx.Is...
2
by: Tomas Deman | last post by:
Hi, I need a fast method for converting an int array to a byte array. At the moment, I'm using this: public static byte Int2ByteArray(int array) { byte lbytRetval = new byte; int lintIdxHi;...
3
by: Joshua Russell | last post by:
Hi, I've got a program (see source below) that makes a file and fills it with random binary values (from 0 to 255). The source below works, however the program creates files at a rate of about...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
8
by: moondaddy | last post by:
I need to convert a byte array to a string and pass it as a parameter in a URL and then convert it back to the original byte array. However, its getting scrambled in the conversion. In short,...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
0
by: shahiz | last post by:
This the error i get when i try to run my program Error: Unable to realize com.sun.media.amovie.AMController@18b81e3 Basically i have a mediapanel class that initialize and play the media as...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
0
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.