Android暂停/恢复录音?

时间:2011-09-08 20:18:47

标签: android voice recording

我见过很多适用于Android的录音教程,但我没有找到暂停/恢复功能的任何教程。

任何人都可以指导我吗?这在Android中是否可行 如果可能,您能提供代码示例吗?

2 个答案:

答案 0 :(得分:4)

AudioRecorder不支持暂停/恢复。您将需要停止并重新启动它。

此外,您还需要连接音频文件:Merging pcm audio files

答案 1 :(得分:1)

    byte fileContent[]=null;
    FileInputStream ins;
    FileOutputStream fos = null;
    try{
        fos = new FileOutputStream(getFilename(),true);
        Log.i(TAG, "OutputFile created");
    }
    catch (FileNotFoundException e1){
        // TODO Auto-generated catch block
        Log.i(TAG, "OutputFile Not created");
        e1.printStackTrace();
    }
    for(int i=1;i<listOfFilesToCombine.size();i+=2){
        try{
            File f=new File(listOfFilesToCombine.get(i));
            Log.v("TAG", "File Length:"+f.length());
            fileContent = new byte[(int)f.length()];
            ins=new FileInputStream(listOfFilesToCombine.get(i));
            int r=ins.read(fileContent);
            Log.v("TAG", "Number Of Bytes Readed:"+r);
            if(i>1){
                byte[] headerlessFileContent = new byte[fileContent.length-6];
                for(int j=6; j<fileContent.length;j++){
                    headerlessFileContent[j-6] = fileContent[j];
                }
                fileContent = headerlessFileContent;
            }
            fos.write(fileContent);         
            Log.v("TAG", "File"+i+"is Appended");
        }
        catch (FileNotFoundException e){
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    try{
        fos.close();
        Log.v("Record Message", "===== Combine File Closed =====");
    }
    catch (IOException e){
        // TODO Auto-generated catch block
        e.printStackTrace();
    }