473,703 Members | 5,970 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem Converting Byte Array to Datasource For JMF

3 New Member
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(Input Stream is){
DataSource ds=new DataSource(is);
player = Manager.createP layer(ds);

//datasource class
import java.io.*;
import java.nio.ByteBu ffer;
import javax.media.*;
import javax.media.pro tocol.*;

public class DataSource extends PullDataSource {
private InputStream is;
private byte [] bytes;

/** Creates new MediaViewerData Source */
public DataSource(Inpu tStream is) {
super();
this.is = is;
try{
int byteCount = is.available();
bytes = new byte [byteCount];
is.read(bytes);
}
catch (Exception e){
System.out.prin tln(e);
}
}

public PullSourceStrea m [] getStreams() {

PullSourceStrea m [] streams = new PullSourceStrea m [1];
InputSourceStre am iss = new InputSourceStre am(new ByteArrayInputS tream(bytes), new FileTypeDescrip tor(ContentDesc riptor.RAW));
streams[0] = iss;
return streams;

}

public void connect() {}

public void disconnect() {}

public String getContentType( ) {
return new String(FileType Descriptor.MPEG );
}

public MediaLocator getLocator() {
return null;
}

public void initCheck() {}

public void setLocator(Medi aLocator source) {}

public void start() {}

public void stop() {}

public Object getControl(Stri ng s){
return null;
}


public Object [] getControls(){
return null;
}

public Time getDuration(){
return null;
}

}

//inputsourcestre am class
import java.io.InputSt ream;
import java.io.IOExcep tion;
import java.nio.ByteBu ffer;

import javax.media.pro tocol.ContentDe scriptor;
import javax.media.pro tocol.PullSourc eStream;
import javax.media.pro tocol.Seekable;
import javax.media.pro tocol.SourceStr eam;

/**
* Build a source stream out of an input stream.
*
* @see DataSource
* @see SourceStream
* @see java.io.InputSt ream
*
* @version %I%, %E%.
*
*/
public
class InputSourceStre am implements PullSourceStrea m, Seekable {

protected InputStream stream;
protected boolean eosReached;
ContentDescript or contentType;
protected ByteBuffer inputBuffer;
/**
* Construct an <CODE>InputSour ceStream</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 InputSourceStre am(InputStream s, ContentDescript or type) {
stream = s;
eosReached = false;
contentType = type;

}

/**
* Get the content type for this stream.
*
* @return content descriptor for the stream.
*/
public ContentDescript or getContentDescr iptor() {
return contentType;
}

/**
* Obtain the content length
*
* @return content length for this stream.
*/
public long getContentLengt h() {
return SourceStream.LE NGTH_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.availabl e() == 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(buf fer, 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(Stri ng controlName) {
return null;
}
public long seek(long where) {
try {
inputBuffer.pos ition((int)(whe re));
return where;
}
catch (IllegalArgumen tException E) {
return this.tell(); // staying at the current position
}
}
public long tell() {
return inputBuffer.pos ition();
}

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 11578
r035198x
13,262 MVP
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 New Member
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 InputSourceStre am 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
13919
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 something like: char chars = "Hello!"; byte bytes = (byte) chars;
5
2846
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) { Byte bytearrayinput = StringAndByteManipulation.ConvertStringToByteArray(textToEncrypt); //DES instance System.Security.Cryptography.TripleDESCryptoServiceProvider des = new
2
2674
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 there any way. Regards, Govind.
2
407
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; int lintIdxLo; for (int i = 0; i < array.GetLength(0); i++)
3
2730
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.5MB per second. There is a serious performance issue with this program. There is a loop within the main loop that generates a buffer of 500 Bytes that are then all written at once. Can anybody tell me how I can improve the performance of the...
0
3937
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. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
8
4197
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, here's the code: ====================================== Dim textConverter As New ASCIIEncoding Dim sParam As String = "This is my cool param" Dim bytParam() As Byte 'load the byte array here...
39
19637
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) What's the difference between these 3 statements: (i) memcpy(&b, &KoefD, n); // this works somewhere in my code
0
3485
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 datasource import java.awt.BorderLayout; import java.awt.Component; import java.io.*; import java.net.URL; import javax.media.*;
0
8763
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9266
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9020
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7878
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6602
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5926
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4435
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2467
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2073
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.