Strange issue in Combining Audio Files and playing in different API versions

后端 未结 2 1090
粉色の甜心
粉色の甜心 2021-01-02 06:32

All , I am using Media Recorder for Recording Audio.

Case 1: If i use Android Version 2.2 installed devices, my recorded audio comb

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-02 07:05

    Foreword: Haven't tested this, but I don't see why it shouldn't work.

    Provided the headers ARE the cause of this problem, you can solve it really easily. Using the code you've given, the encoding is AMR-NB. According to this document the AMR header is simply the first 6 bytes, which are 0x23, 0x21, 0x41, 0x4D, 0x52, 0x0A. If the headers in subsequent files are causing the issue, simply omit those bytes from subsequent files e.g.

    write all bytes of first file
    write from byte[6] -> byte[end] of subsequent files
    

    Let me know how it goes.

    EDIT: At request, change the try block to:

    try{
            File f=new File(audNames.get(i));
            Log.v("Record Message", "File Length=========>>>"+f.length());
            fileContent = new byte[(int)f.length()];
    
            ///////////////new bit////////
    
            //same as you had, this opens a byte stream to the file
            ins=new FileInputStream(audNames.get(i));
            //reads fileContent.length bytes
            ins.read(fileContent);
            //now fileContent contains the entire audio file - in bytes.
            if(i>0){
                //we are not writing the first audio recording, but subsequent ones
                //so we don't want the header included in the write
    
                //copy the entire file, but not the first 6 bytes
                byte[] headerlessFileContent = new byte[fileContent.length()-6];
                for(int j=6; j>>"+r);
            fos.write(fileContent);//Write the byte into the combine file.
    
            Log.v("Record Message", "File======="+i+"is Appended");
    
        }
    

提交回复
热议问题