2

My Android app records audio in both AMR and WAV format. And my application needs to insert second recorded audio file inside the first one at a position where it is paused. I did it right with WAV files, but the AMR file after insertion is not able to be played in Android MediaPlayer, it gives some error when it reaches the inserted position.But the same file plays fine in AMR players.

The steps I followed are:

1.Writing the data from file1 upto pause position:

raf3=new RandomAccessFile(result,"rw");
raf3.setLength(0);
int d=0;
//Write data from record1 upto the pause position
while(d!=pos)
{
raf3.write(bytes[d]);
d++;
}

2.Writing the data to be inserted from file2

//write all the data from record 2 
int l=0;
raf3.writeBytes(" ");
while(l!=bytesread1)
{
raf3.write(bytes1[l]);
l++;
}

3.Writing the remaining data from file1 after pause position

while(d!=size){
raf3.write(bytes[d]);
d++;
}

Is there anything wrong with what I have done?

User97693321
  • 3,336
  • 7
  • 45
  • 69

1 Answers1

0

You can't necessarily replace data in a compressed stream (AMR, MP3, AAC, etc) with new data, even if the new data is compressed with the same algorithm.
For such replacement to be guaranteed to work you'd need to decompress the data, do the replacement, and the compress it again. This will most likely lead to further degradation of the audio quality.

Michael
  • 57,169
  • 9
  • 80
  • 125