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
New Developer
Posts: 17
Registered: ‎02-17-2009
My Device: Not Specified

Why the player can´t play all the audio buffered in a ByteArrayInputStream ??

Hi all!

 

I have a thread that gets a byte[] from a shared synchronized objet, and then pass it to a new ByteArrayInputStream that I create. The synchronized object has a ByteArrayOutputStream where buffer data recorded by another thread.

 

 

byte[] aux = theData.getDatos();    // getDatos return out.toByteArray()

byte[] copy = new byte[aux.length];
               
for(int i=0 ; i< aux.length - 1 ; i++)
{
       copy[i] = aux[i];
}

 

theInput = new ByteArrayInputStream(copy);

 

 

If I get the copy.length , I can see that it's correct.

After this I create the player:

 

 

if ( theInput.available() > 0 )
{

      player = Manager.createPlayer(theInput, "audio/amr");

      System.out.println("##### Before REALIZE "+ theInput.available()+" BYTES");
      player.realize();

      System.out.println("##### Before PREFECTCH "+ theInput.available()+" BYTES");
      player.prefetch();

      System.out.println("##### Before START "+ theInput.available()+" BYTES");
      player.start();       

      System.out.println("##### PLAYING ....."+ theInput.available());

// sleep time enough for play all data ( the data are around 15 seconds)

     sleep(20000);         

     player.deallocate();
     player.close();
     theInput.close();

}

 

 

 

I think that all this above is correct, but the player just plays three seconds and stop! the output of debug shows:

 

##### Before REALIZE 15320 BYTES

##### Before PREFETCH 0 BYTES

##### Before START 0 BYTES

##### PLAYING .....

MN: getPlayableStreams0(1000000)=1
MN: getLength0(1000000)=-1
MN: getPlayableStreams0(1000000)=1
MN: isSeekable0(1000000)=1
AR: add source 10
AR: setAudioMode 32
MN: play0(1000000) is audio, NO check for active pause
MN: play0(1000000)=0
MN: MEDIA_STOPPED received
MN: handle=1000000 staticsHandle=7fffffff
MN: unload0(1000000)=2 pauseHandle=7fffffff
AR: remove source 10
AR: setAudioMode 32
Streaming done reason=1 prev-state=300

.

.

I don´t understand why before perform the realize method,the buffer turn to 0, I try even remove the realize and prefetch calls and although output shows ##### Before START 15320 BYTES , it still playing three seconds!

 

Anyone understand what is happens??

 

Thanks and best regards!!

 

 

 

 

New Developer
Posts: 17
Registered: ‎02-17-2009
My Device: Not Specified

Re: Why the player can´t play all the audio buffered in a ByteArrayInputStream ??

Hi everybody !

I discover this:

The recorder data thread, record through a player which start record and sleep 3000 ms (3 seconds) and then commit and write data in the share object, all this while player isn`t closed. I can see that the data is being accumulated, but when the above player thread try reproduce all accumulated data in the buffer, it only reproduce the fist recorded (the fist 3 seconds) !!

 

This is how I record:

 

while (thePlayer.getState() != Player.CLOSED)
 {
            int size;
            theRcontrol = (RecordControl) thePlayer.getControl("RecordControl");
            theOutput = new ByteArrayOutputStream();
            theRcontrol.setRecordStream(theOutput);
            theRcontrol.startRecord();
            thePlayer.start();
            System.out.println("##### RECORDING.....");
           
            sleep(3000);

            theRcontrol.commit();
            theOutput.flush();
           
            size = theOutput.size();
            byte[] auxArray = new byte[theOutput.toByteArray().length];
           
            for(int i=0 ; i<
auxArray.length - 1 ; i++)
            {
               
auxArray [i] = theOutput.toByteArray()[i];
            }

            System.out.println("##### RECORDED " +size+ " Bytes");

 

            // Write in the shared and synchronized object

            theData.setDatos(auxArray);
           
            theOutput.close();
            theRcontrol.reset();
            thePlayer.stop();
  }

 

 

theData is the shared and synchronized object and has a ByteArrayOutputStream member, theData.setDatos( auxArray )

just write the array in this ByteArrayOutputStream which belongs theData:

 

baos.write( chorroBytes);

baos.flush();

 

I can't understand why the player plays only 3 seconds if the array has bytes for plays more than 3 seconds.

I hope that someone can help me about this, It's driving me crazy, and need this works for my job.

 

Thanks everybody, and regards.

New Developer
Posts: 17
Registered: ‎02-17-2009
My Device: Not Specified

Re: Why the player can´t play all the audio buffered in a ByteArrayInputStream ??

I realize that every time I take a record in my while (thePlayer.getState() != Player.CLOSED), theOutput.ToByteArray() always contains the following values at the fist positions of the byte array: 35,33,65,77,82,10,60 

So every record commited in the ByteArrayOutputStream starts with this values.

 

Could be this the reason why the player only plays the frist record of all ??

 

Thank!

New Developer
Posts: 17
Registered: ‎02-17-2009
My Device: Not Specified

Re: Why the player can´t play all the audio buffered in a ByteArrayInputStream ??

I've been reading the RFC 4867 and I discover that the ascii values 35 33 65 77 82 10 mean #!AMR. It is a header, so when I take a record and I get the byte [] from the ByteArrayOutputStream for write it in the shared ByteArrayInpuntStream, I do it writing the byte[] without this header. But I've the same problem, the player only plays the first record of all.

 

Are there any way to record several times in the same ByteArrayOutputStream without use commit ??

Commit ends the recording, so if I want a new recording, this recording will have a new header...and I don't want it.

 

Could someone enlighten me about this? I really worried with this. I'm beginning to think that people is right saying that girls aren't good developers Smiley Sad

BlackBerry Development Advisor
Posts: 15,784
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Why the player can´t play all the audio buffered in a ByteArrayInputStream ??

When you call commit it completes the recording.  The next recording you make will be completely new.  Each recording creates a single, stand alone file.

 

You can use the RecordControl.stopRecord and RecordControl.startRecord methods to start and stop recording.  Once you have finished recording you can call commit and have the entire recording available as a single file.

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 Developer
Posts: 17
Registered: ‎02-17-2009
My Device: Not Specified

Re: Why the player can´t play all the audio buffered in a ByteArrayInputStream ??

Thanks MSohm!

I realized it, but the problem is that I need get the recording data anytime from another thread, so I can't get that data without call commit.

As far I can see, there is no way to get the data without commit.

 

Thanks all !

Highlighted
Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: Why the player can´t play all the audio buffered in a ByteArrayInputStream ??

still interested ?

I guess not. but someone else might be.

 

you can call toByteArray(), and then reset() on the OutputStream



"Listen carefully, I shall say this only once"