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
BlackBerry Development Advisor
Posts: 15,697
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Bug in media Manager/Player

Can you try again now? I had the Issue Tracker admin look into this and it should be fixed now.
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
Contributor
Posts: 40
Registered: ‎01-14-2011
My Device: Not Specified

Re: Bug in media Manager/Player

Code snippet for doing record:

 

FileConnection fco = (FileConnection) Connector.open("file:///store/home/user/test_audio");
if (!fco.exists()) fco.create(); // create the file if it doesn't exist
fco.truncate(0); //clear it if it does
OutputStream os = fco.openOutputStream();
//Write out header without size info
writeRIFFChunk(os, 0);
writeFmtChunk(os);
writeDataChunk(os, 0);
recordControl.setRecordStream(os);
recordControl.startRecord();
recordPlayer.start();

 

When yuo've finished recording go back and update header:

 

//Get filesize
fco = (FileConnection) Connector.open("file:///store/home/user/test_audio");
long fileSize = fco.fileSize();

//Re-write header
os = fco.openDataOutputStream();
writeRIFFChunk(os, fileSize);
writeFmtChunk(os);
writeDataChunk(os, fileSize);
os.close();
fco.close();

 

 

and to lpayback:

 

FileConnection fci = (FileConnection) Connector.open("file:///store/home/user/test_audio"); // Method B
InputStream is = fci.openInputStream(); // Method B
Player playPlayer = Manager.createPlayer(is, "audio/x-wav"); // Method B
playPlayer.start();

 

And it plays beautifully.

 

 

The crucial support methods:

        public void writeRIFFChunk(OutputStream os, long fileSize) throws IOException{

os.write(new byte[] {(byte) 0x52, (byte) 0x49, (byte) 0x46, (byte) 0x46}); //ChunkID
int chunkSize = (int)(fileSize - 8);
os.write(chunkSize & 0xFF);
os.write((chunkSize >> 8) & 0xFF);
os.write((chunkSize >> 16) & 0xFF);
os.write((chunkSize >> 24) & 0xFF);
os.write(new byte[] {(byte) 0x57, (byte) 0x41, (byte) 0x56, (byte) 0x45}); //Format
}

public void writeFmtChunk(OutputStream os) throws IOException{
os.write(new byte[] {(byte) 0x66, (byte) 0x6d, (byte) 0x74, (byte) 0x20}); //Subchunk1ID
os.write(new byte[] {(byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00}); //Subchunck1Size
os.write(new byte[] {(byte) 0x01, (byte) 0x00}); //AudioFormat
os.write(new byte[] {(byte) 0x01, (byte) 0x00}); //NumChannels
os.write(new byte[] {(byte) 0x40, (byte) 0x1F, (byte) 0x00, (byte) 0x00}); //SampleRate
os.write(new byte[] {(byte) 0x80, (byte) 0x3E, (byte) 0x00, (byte) 0x00}); //ByteRate
os.write(new byte[] {(byte) 0x02, (byte) 0x00}); //BlockAlign
os.write(new byte[] {(byte) 0x10, (byte) 0x00}); //BitsPerSamlpe
}

public void writeDataChunk(OutputStream os, long fileSize) throws IOException{

os.write(new byte[] {(byte) 0x64, (byte) 0x61, (byte) 0x74, (byte) 0x61}); //Subchunk2ID
int chunkSize = (int)(fileSize - 44);
os.write(chunkSize & 0xFF);
os.write((chunkSize >> 8) & 0xFF);
os.write((chunkSize >> 16) & 0xFF);
os.write((chunkSize >> 24) & 0xFF);
}

 



Super Contributor
Posts: 308
Registered: ‎05-31-2011
My Device: Blackberry-SDK-9800
My Carrier: SimPakage 6.0.0.337_9800 asia.exe

Re: Bug in media Manager/Player

hello mark,

    u mean to say if v need to append wav file like to add the byte[]  to end of file.... v can use file connection 

and outputstream... 

  there is no need to remove the header of wav file to append the wav file.

     actually i am building application record aand pause.... in which after pause event, the byte[] must be added to end of exixting wav file.. 

    i got the problem while doing the same, 1st pary of wav fille is properly playing, but second part, means appended byte[] will not play.... 

   Shall i send my code.

 

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

Re: Bug in media Manager/Player

You would need to remove the header here and potentially update the header of the original file.  Writing to a file as you describe would append a second complete wav file to the end of the first.

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