Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
udik
Posts: 136
Registered: ‎03-04-2009
My Device: Not Specified

Getting Exception when playing WAV file

Hi,

 

I'm getting the following debug log when playing some WAV files from different URLs in a loop. I read the WAV files first using ByteArrayOutputStream and then call the javax.microedition.media.Player on each stream, any help would be appreciated! Note that the files are actually being played fine, albeit with large delay in between:

 

-----------------------------------------------------------------------------------------------------------

[STREAM] allocating big buffer [index: 0] [numStreams: 0]
[STREAM] allocating stream [index: 0] [size: 327680]
[STREAM] allocated stream [index: 0] [handle: 1799] [size: 327680]
SMP:smileyfrustrated:treaming session aquired id=1799
MN: init0(0)=0
MN: load 0
AUDIOMANAGER: IOException
+++mediaError():MEDIA_LOADING (net.rim.device.internal.media.MediaPlayer@cea8aca3)
+++unloadCleanup():MEDIA_LOADING (net.rim.device.internal.media.MediaPlayer@cea8aca3)
MEDIA_PLAYER(-1): Setting state to:MEDIA_UNLOADED (net.rim.device.internal.media.MediaPlayer@cea8aca3) from:MEDIA_LOADING (net.rim.device.internal.media.MediaPlayer@cea8aca3)
---unloadCleanup():MEDIA_UNLOADED (net.rim.device.internal.media.MediaPlayer@cea8aca3)
---mediaError():MEDIA_UNLOADED (net.rim.device.internal.media.MediaPlayer@cea8aca3)
Error initializing media, state is not MEDIA_LOADED: MEDIA_UNLOADED (net.rim.device.internal.media.MediaPlayer@cea8aca3)
inside play loooooooop: Error initializing media.
Streaming done reason=1 prev-state=300
SMP:smileyfrustrated:treaming session aquired id=1799
MN: init0(16777216)=0
MN: load 1
AUDIOMANAGER: IOException
+++mediaError():MEDIA_LOADING (net.rim.device.internal.media.MediaPlayer@231ab4b0)
+++unloadCleanup():MEDIA_LOADING (net.rim.device.internal.media.MediaPlayer@231ab4b0)

------------------------------------------------------------------------------------------------------------

 

Developer
acowart
Posts: 163
Registered: ‎07-16-2008
My Device: Not Specified

Re: Getting Exception when playing WAV file

Could we see the code used to create the player in this loop?
Andrew Cowart | Metova
www.metova.com
Developer
udik
Posts: 136
Registered: ‎03-04-2009
My Device: Not Specified

Re: Getting Exception when playing WAV file

Hi Andrew,

 

Sure you can, here it is,

 

Thanks!

Udi

 

-----------------------------------------------------------

 

for (int mCount = loginId.length - 1; mCount >= 0; mCount--) {
                          try {       
                             String murl = new String("http://192.168.0.111:8080/examples/jsp/msg-" + Integer.toString(mCount) + ".wav");
                             //String murl = new String("http://192.168.0.111:8080/examples/jsp/msg-0.wav");
           
                             // Open connection to the http url...
                             HttpConnection connection = (HttpConnection) Connector.open(murl);
                             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(murl, Connector.READ_WRITE);
                             javax.microedition.media.Player player =
                                javax.microedition.media.Manager.createPlayer(byteIn, "audio/wav");
                            
                             player.realize();
                             player.prefetch();
                             player.start();
                             while(player.getState() != 300) {
                                System.out.println("plaaaaaaaaaaaaaaaaaaatying ..... status: " + player.getState());
                                Thread.sleep(500);;
                             }
                             player.stop();
                             player.deallocate();
                             player.close();
                             byteIn.close();
                             Thread.sleep(1000);
                             System.gc();
                           }
                           catch(Exception e) {
                              System.out.println("inside play loooooooop: " + e.getMessage());
                           } 
                       }
-------------------------------------------------------------------------

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Getting Exception when playing WAV file

What BlackBerry Smartphone model and BlackBerry handheld software version are you testing on?  You can find this under Options, About on the BlackBerry Smartphone.  What line of code is triggering the IOException?
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Contributor
raju554
Posts: 7
Registered: ‎02-15-2010
My Device: Not Specified

Re: Getting Exception when playing WAV file

Hi,

I am also stuck with the same issue.. I tested my application on both 9000 device simulator with 4.6 os and 9630 device simulator with 4.7.1 os.

I get the same trace of statements in the console during execution.

Please help me out..

Thanks, raju.

Developer
Aviator168
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930

Re: Getting Exception when playing WAV file

I would write the file to the SDCard and see if it would be opened with the media player that came with the device. I have the same code (almost) working. Except that I create input stream to the player instead of from a http connection.

New Contributor
raju554
Posts: 7
Registered: ‎02-15-2010
My Device: Not Specified

Re: Getting Exception when playing WAV file

Hi Aviator, Nice to see ur reply...

Can't we stream the file instead of saving the file onto the SD Card.

The BufferedPlayblackdemo sample has not worked either on the simulators 9000 and 9630.