将录制的音频(AMR 和 WAV)文件插入另一个文件中
我的 Android 应用程序以 AMR
和 WAV
格式录制音频。我的应用程序需要将第二个录制的音频文件插入第一个文件中暂停的位置。我对 WAV
文件做对了,但是插入后的 AMR
文件无法在 Android MediaPlayer 中播放,当到达插入位置时会出现一些错误。但是相同的文件在 AMR 播放器中可以正常播放。
我遵循的步骤是:
1.从file1写入数据到暂停位置:
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.从file2写入要插入的数据
//write all the data from record 2
int l=0;
raf3.writeBytes(" ");
while(l!=bytesread1)
{
raf3.write(bytes1[l]);
l++;
}
3.在暂停位置之后写入file1的剩余数据
while(d!=size){
raf3.write(bytes[d]);
d++;
}
我所做的有什么问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
即使新数据是使用相同的算法压缩的,您也不一定能用新数据替换压缩流(AMR、MP3、AAC 等)中的数据。
为了保证此类替换有效,您需要需要解压数据,进行替换,然后再次压缩。这很可能会导致音频质量进一步下降。
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.