473,507 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JMF Datasource problem..i need help with this one error

3 New Member
This the error i get when i try to run my program
Expand|Select|Wrap|Line Numbers
  1. Error: Unable to realize com.sun.media.amovie.AMController@18b81e3
  2.  
Basically i have a mediapanel class that initialize and play the media as datasource
Expand|Select|Wrap|Line Numbers
  1. import java.awt.BorderLayout;
  2. import java.awt.Component;
  3. import java.io.*;
  4. import java.net.URL;
  5. import javax.media.*;
  6. import javax.swing.JPanel;
  7. import java.nio.ByteBuffer;
  8.  
  9. public class MediaPanel extends JPanel
  10. {
  11.    InputStream stream;
  12.    String name = "";
  13.    ByteBuffer inputBuffer;
  14.    byte[] store = null;
  15.  
  16.    public MediaPanel( InputStream in )
  17.    {    
  18.    try{
  19.          this.stream = in;
  20.          //store stream as ByteBuffer
  21.          store = new byte[stream.available()];
  22.       stream.read(store);
  23.       inputBuffer.allocate(store.length);
  24.       inputBuffer.wrap(store);
  25.          //get contentType
  26.          DrmDecryption drm = new DrmDecryption();
  27.          name = drm.naming;
  28.  
  29.       setLayout( new BorderLayout() ); // use a BorderLayout
  30.  
  31.       ByteBufferDataSource ds = new ByteBufferDataSource(inputBuffer,name);
  32.  
  33.       // Use lightweight components for Swing compatibility
  34.       Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, true );
  35.  
  36.          // create a player to play the media specified in the URL
  37.          Player mediaPlayer = Manager.createRealizedPlayer(ds);
  38.  
  39.          // get the components for the video and the playback controls
  40.          Component video = mediaPlayer.getVisualComponent();
  41.          Component controls = mediaPlayer.getControlPanelComponent();
  42.  
  43.          if ( video != null ) 
  44.             add( video, BorderLayout.CENTER ); // add video component
  45.  
  46.          if ( controls != null ) 
  47.             add( controls, BorderLayout.SOUTH ); // add controls
  48.  
  49.          mediaPlayer.start(); // start playing the media clip
  50.        }catch(Exception e){}
  51.    } // end MediaPanel constructor
  52. } // end class MediaPanel
The ByteBufferDataSource class is use to create the datasource for the player
Expand|Select|Wrap|Line Numbers
  1. import javax.media.protocol.ContentDescriptor;
  2. import javax.media.protocol.PullDataSource;
  3.  
  4. import java.nio.ByteBuffer;
  5. import java.io.IOException;
  6.  
  7. import javax.media.MediaLocator;
  8. import javax.media.Duration;
  9. import javax.media.Time;
  10.  
  11.  
  12. public class ByteBufferDataSource extends PullDataSource {
  13.  
  14. protected ContentDescriptor contentType;
  15. protected SeekableStream[] sources;
  16. protected boolean connected;
  17. protected ByteBuffer anInput;
  18.  
  19. protected ByteBufferDataSource(){
  20. }
  21.  
  22. /**
  23. * Construct a ByteBufferDataSource from a ByteBuffer.
  24. * @param source The ByteBuffer that is used to create the
  25. * the DataSource.
  26. */
  27. public ByteBufferDataSource(ByteBuffer input, String contentType) throws IOException {
  28. anInput = input;
  29. this.contentType = new ContentDescriptor(
  30.                ContentDescriptor.mimeTypeToPackageName(contentType));
  31.  
  32. }
  33.  
  34. /**
  35. * Open a connection to the source described by
  36. * the ByteBuffer/CODE>.
  37.  
  38. *
  39. * The connect method initiates communication with the source.
  40. *
  41. * @exception IOException Thrown if there are IO problems
  42. * when connect is called.
  43. */
  44. public void connect() {
  45. sources = new SeekableStream [1];
  46. sources[0] = new SeekableStream(anInput);
  47. }
  48.  
  49. /**
  50. * Close the connection to the source described by the locator.
  51.  
  52.  
  53. * The disconnect method frees resources used to maintain a
  54. * connection to the source.
  55. * If no resources are in use, disconnect is ignored.
  56. * If stop hasn't already been called,
  57. * calling disconnect implies a stop.
  58. *
  59. */
  60. public void disconnect() {
  61. }
  62.  
  63. /**
  64. * Get a string that describes the content-type of the media
  65. * that the source is providing.
  66.  
  67.  
  68. * It is an error to call getContentType if the source is
  69. * not connected.
  70. *
  71. * @return The name that describes the media content.
  72. */
  73. public String getContentType() {
  74. return contentType.getContentType();
  75. }
  76.  
  77. public Object getControl(String str) {
  78. return null;
  79. }
  80.  
  81. public Object[] getControls() {
  82. return new Object[0];
  83. }
  84.  
  85. public javax.media.Time getDuration() {
  86. return Duration.DURATION_UNKNOWN;
  87. }
  88.  
  89. /**
  90. * Get the collection of streams that this source
  91. * manages. The collection of streams is entirely
  92. * content dependent. The MIME type of this
  93. * DataSource provides the only indication of
  94. * what streams can be available on this connection.
  95. *
  96. * @return The collection of streams for this source.
  97. */
  98. public javax.media.protocol.PullSourceStream[] getStreams() {
  99. return sources;
  100. }
  101.  
  102. /**
  103. * Initiate data-transfer. The start method must be
  104. * called before data is available.
  105. *(You must call connect before calling start.)
  106. *
  107. * @exception IOException Thrown if there are IO problems with the source
  108. * when start is called.
  109. */
  110. public void start() throws IOException {
  111. }
  112.  
  113. /**
  114. * Stop the data-transfer.
  115. * If the source has not been connected and started,
  116. * stop does nothing.
  117. */
  118. public void stop() throws IOException {
  119. }
  120. }
Here is where my problem lies, i have a SeekableStream to manipulate the control of the streaming position.
Expand|Select|Wrap|Line Numbers
  1. import java.lang.reflect.Method;
  2. import java.lang.reflect.Constructor;
  3.  
  4. import java.io.IOException;
  5. import java.nio.ByteBuffer;
  6. import java.nio.BufferUnderflowException;
  7.  
  8.  
  9. import javax.media.protocol.PullSourceStream;
  10. import javax.media.protocol.Seekable;
  11. import javax.media.protocol.ContentDescriptor;
  12.  
  13. public class SeekableStream implements PullSourceStream, Seekable {
  14.  
  15.  
  16. protected ByteBuffer inputBuffer;
  17.  
  18. /**
  19. * a flag to indicate EOF reached
  20. */
  21.  
  22.  
  23. /** Creates a new instance of SeekableStream */
  24. public SeekableStream(ByteBuffer byteBuffer) {
  25. inputBuffer = byteBuffer;
  26. this.seek((long)(0)); // set the ByteBuffer to to beginning
  27. }
  28.  
  29. /**
  30. * Find out if the end of the stream has been reached.
  31. *
  32. * @return Returns true if there is no more data.
  33. */
  34. public boolean endOfStream() {
  35. return (! inputBuffer.hasRemaining());
  36. }
  37.  
  38. /**
  39. * Get the current content type for this stream.
  40. *
  41. * @return The current ContentDescriptor for this stream.
  42. */
  43. public ContentDescriptor getContentDescriptor() {
  44. return null;
  45. }
  46.  
  47. /**
  48. * Get the size, in bytes, of the content on this stream.
  49. *
  50. * @return The content length in bytes.
  51. */
  52. public long getContentLength() {
  53. return inputBuffer.capacity();
  54. }
  55.  
  56. /**
  57. * Obtain the object that implements the specified
  58. * Class or Interface
  59. * The full class or interface name must be used.
  60.  
  61.  
  62. *
  63. * The control is not supported.
  64. * null is returned.
  65. *
  66. * @return null.
  67. */
  68. public Object getControl(String controlType) {
  69. return null;
  70. }
  71.  
  72. /**
  73. * Obtain the collection of objects that
  74. * control the object that implements this interface.
  75.  
  76.  
  77. *
  78. * No controls are supported.
  79. * A zero length array is returned.
  80. *
  81. * @return A zero length array
  82. */
  83. public Object[] getControls() {
  84. Object[] objects = new Object[0];
  85.  
  86. return objects;
  87. }
  88.  
  89. /**
  90. * Find out if this media object can position anywhere in the
  91. * stream. If the stream is not random access, it can only be repositioned
  92. * to the beginning.
  93. *
  94. * @return Returns true if the stream is random access, false if the stream can only
  95. * be reset to the beginning.
  96. */
  97. public boolean isRandomAccess() {
  98. return true;
  99. }
  100.  
  101. /**
  102. * Block and read data from the stream.
  103.  
  104.  
  105. * Reads up to length bytes from the input stream into
  106. * an array of bytes.
  107. * If the first argument is null, up to
  108. * length bytes are read and discarded.
  109. * Returns -1 when the end
  110. * of the media is reached.
  111. *
  112. * This method only returns 0 if it was called with
  113. * a length of 0.
  114. *
  115. * @param buffer The buffer to read bytes into.
  116. * @param offset The offset into the buffer at which to begin writing data.
  117. * @param length The number of bytes to read.
  118. * @return The number of bytes read, -1 indicating
  119. * the end of stream, or 0 indicating read
  120. * was called with length 0.
  121. * @throws IOException Thrown if an error occurs while reading.
  122. */
  123. public int read(byte[] buffer, int offset, int length) throws IOException {
  124.  
  125. // return n (number of bytes read), -1 (eof), 0 (asked for zero bytes)
  126.  
  127. if ( length == 0 )
  128. return 0;
  129. try {
  130. inputBuffer.get(buffer,offset,length);
  131. return length;
  132. }
  133. catch ( BufferUnderflowException E ) {
  134. return -1;
  135. }
  136. }
  137.  
  138. public void close() {
  139.  
  140. }
  141. /**
  142. * Seek to the specified point in the stream.
  143. * @param where The position to seek to.
  144. * @return The new stream position.
  145. */
  146. public long seek(long where) {
  147. try {
  148. inputBuffer.position((int)(where));
  149. return where;
  150. }
  151. catch (IllegalArgumentException E) {
  152. return this.tell(); // staying at the current position
  153. }
  154. }
  155.  
  156. /**
  157. * Obtain the current point in the stream.
  158. */
  159. public long tell() {
  160. return inputBuffer.position();
  161. }
  162.  
  163. /**
  164. * Find out if data is available now.
  165. * Returns true if a call to read would block
  166. * for data.
  167. *
  168. * @return Returns true if read would block; otherwise
  169. * returns false.
  170. */
  171. public boolean willReadBlock() {
  172. return (inputBuffer.remaining() == 0);
  173. }
  174. }
Feb 27 '08 #1
0 3474

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

Similar topics

0
4590
by: Jesse Martinez | last post by:
My problem occurs when I use an ArrayList as a ListBox.DataSource. When the ArrayList attached to the Listbox is not empty the Listbox behave normal without problem, but if I remove all items...
2
2104
by: | last post by:
Hello All, I am having a lot of difficulty trying to bind a templated column, that is programmatically created for a datagrid, to a datasource column. I have a datasource containing 2 columns,...
6
1944
by: vips | last post by:
Page_Load datagrid1.datasource=dataset1 //I am filling the datagrid and it works fine when page is displayed end ---------------
7
34751
by: TJoker .NET | last post by:
I'm developing an VB.NET Windows Forms application that uses CR for VS.NET (original version shipped with VS.NET 2002 - my VS.NET has the latest SP installed, no SPs for CR). My reports get their...
11
8533
by: Zorpiedoman | last post by:
The problem is this: I have a list box. I set an array list as the datasource. I remove an item from the array list. I set the listbox datasource to nothing. I set the listbox datasource to...
4
13475
by: Jim Katz | last post by:
I have an application that updates a strongly typed data set at run time. I'd like to dynamically create a table that connects to a run time data table. For displaying the data, this works well. ...
4
10110
by: SHEBERT | last post by:
Here is an example of a SortedList that works as a datasource to the ComboBox and a generic SortedList<that does not works as a datasource to the ComboBox. Why? If I use List and generic List<>,...
1
1765
by: webcat | last post by:
Hi All, another day another problem! I have a SQL table shown on a form which i wish to filter by current logged in user - I have a local table storing the currently logged in user and all...
2
11563
by: shahiz | last post by:
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...
0
7223
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,...
0
7110
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7314
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,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7030
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...
0
7482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
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,...
0
4702
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...
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.