0
votes

I'm new to audio format.

I'm trying to play audio data on device A as I receive it from device B , chunk by chunk. The problem is simply playing chunk by chunk does not produce any sound. If I combine all the chunks and then play, it works fine. But I want to make the application play real-time data, meaning I want to play the partial audio data the moment I receive it, even though the compete audio file has not been sent. I guess the chunk has to be in certain format to be played.

I searched on the net and learnt that MPEG_4 can be played in chunks as long as every chunk has a header. I wonder if it's possible that I add a header to each chunk manually.

I tried to record multiple samples and noticed they all have common bytes at the beginning as below:

0000 0018 6674 7970 6d70 3432 0000 0000
6973 6f6d 6d70 3432 0000 ....the rest..

Are these common bytes the header ? I wonder if there is a certain way that device A can tell if a certain chunk can be played so I can play the chunk as soon as I receive it ?

Any thought on this question would help! Thanks in advance!

1

1 Answers

0
votes

I would like to answer the question myself.

First of all, do not stick with MediaPlayer as it can not record PCM file.

Actually a PCM file satisfies all the requirement since it applies a raw file format (meaning it is not compressed). One can play the PCM file frame by frame. The size of the frame(e.g. 640 bytes) is fixed once the sampling rate and other params are defined in the recorder and player.

Also checkout AudioRecord and AudioTrack class as it can record and play PCM files.