Android перекодирует голос и ловит исключение java.io.FileNotFoundException - PullRequest
0 голосов
/ 20 мая 2018

Я хочу записать голос , и смешать mp3-файл, но он не может найти файл

Я добавил разрешение по использованию-разрешения android: name = "android.permission.WRITE_EXTERNAL_STORAGE".

это мой код

File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator + Global.gContext.getResources().getString(R.string.PATH)+ File.separator + "Luyin");
if(!f.exists()){
    f.mkdir();
}
String voiceName = f + File.separator;
String sound = Global.UserNumber+"-"+System.nanoTime()+"";
List<String> soundList = new ArrayList<String>();
private void stop() {
            mRecorder.stop();
            heBingMp3();
            File f = new File(voiceName+sound+".mp3");
            if(!f.exists()){
                Global.show("请先录制声音");
                return;
            }
            wancheng = true;
            alertDialog.setMessage("正在合成,请稍后……");
            alertDialog.show();
            new DecodeAudioTask(voiceName+sound+".mp3").execute(); 
}
public void heBingMp3(){
            File f=new File(voiceName+sound+".mp3");
            for(int i=0;i<soundList.size();i++){  
                try {
                    File file=new File(soundList.get(i));
                    FileInputStream in=new FileInputStream(file);
                    FileOutputStream out=new FileOutputStream(f,true);
                    byte bs[]=new byte[1024*4];
                    int len=0;

                    while((len=in.read(bs))!=-1){
                        out.write(bs,0,len);
                    }
                    in.close();
                    out.close();
                    file.delete();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
}
try {
mRecorder = new MP3Recorder(new 
File(Environment.getExternalStorageDirectory(),voiceName+ File.separator+"temp"+ 
File.separator + sound + soundNum+".mp3"));
mRecorder.start();
} catch (IOException e) {
    e.printStackTrace();
}

soundList.add (voiceName + File.separator + "temp" + File.separator + sound + soundNum + ". Mp 3");

...