Android:没有找到这样的文件或目录错误?

时间:2017-04-06 03:01:57

标签: java android audio-recording audio-fingerprinting

我正在播放和录制音频,以便使用musicg API进行音频匹配分析。每次运行我的应用程序时,我都会收到以下错误:

V/playRecordAudio: Playing sound & recording stopped
 W/System.err: java.io.FileNotFoundException: /storage/emulated/0: open failed: EISDIR (Is a directory)
W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:452)
W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:127)
W/System.err:     at java.io.FileOutputStream.<init>(FileOutputStream.java:116)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment.copyWaveFile(SpeakersFragment.java:316)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment.stopRecording(SpeakersFragment.java:284)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment.access$200(SpeakersFragment.java:45)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment$3.onCompletion(SpeakersFragment.java:176)
W/System.err:     at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:2821)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err:     at android.os.Looper.loop(Looper.java:148) 
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5417)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
W/System.err: Caused by: android.system.ErrnoException: open failed: EISDIR (Is a directory)
W/System.err:     at libcore.io.Posix.open(Native Method)
W/System.err:     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:438)
W/System.err:   ... 14 more
W/System.err: java.io.FileNotFoundException: /storage/emulated/0/AudioRecorder/1491446370522.wav: open failed: ENOENT (No such file or directory)
W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:452)
W/System.err:     at java.io.FileInputStream.<init>(FileInputStream.java:76)
W/System.err:     at java.io.FileInputStream.<init>(FileInputStream.java:103)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment.getScore(SpeakersFragment.java:399)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment.stopRecording(SpeakersFragment.java:285)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment.access$200(SpeakersFragment.java:45)
W/System.err:     at com.android.project1.main.fragments.SpeakersFragment$3.onCompletion(SpeakersFragment.java:176)
W/System.err:     at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:2821)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err:     at android.os.Looper.loop(Looper.java:148)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5417)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
 W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
W/System.err: Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
W/System.err:     at libcore.io.Posix.open(Native Method)
W/System.err:     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:438)
W/System.err:   ... 13 more
I/System.out: 0.0
W/MediaPlayer: mediaplayer went away with unhandled events

我正在尝试将录制文件保存到文件中,然后将其传递给getScore()方法,以便将其与播放的原始音频文件进行比较并返回匹配的分数。下面是我的MainActivity中的相关代码,其中的行以粗体显示错误。

编辑1:

String mFileName = getFilename();
...
private void stopRecording() {
            if (null != recorder) {
                isRecording = false;

                int i = recorder.getState();
                if (i == 1)
                    recorder.stop();
                recorder.release();

                recorder = null;
                recordingThread = null;
            }

            copyWaveFile(getTempFilename(), mFileName);
            getScore(); //error here
            deleteTempFile();
        }

public void getScore (){

            String fileName1 = mFileName;
            String fileName2 = "R.raw.forrest_gump_theme"; //Need to change this

            try {
                //InputStream fis1 = null, fis2 = null;
                InputStream fis1, fis2;
                fis1 = new FileInputStream(fileName1);//error here
                fis2 = new FileInputStream(fileName2);

                Wave wave1 = new Wave(fis1), wave2 = new Wave (fis2);
                FingerprintSimilarity similarity;

                similarity = wave1.getFingerprintSimilarity(wave2);
                result = similarity.getSimilarity()*100;


            }catch (Exception e){
                e.printStackTrace();
            }
            System.out.println(result);
        }

1 个答案:

答案 0 :(得分:1)

我认为问题出在copyWaveFile():

您正在将mFileName变量发送到copyWaveFile(),但使用以下代码更改其路径:

 outFilename = Environment.getExternalStorageDirectory().getPath();

尝试删除上面的行并再次检查。如果同样的错误仍然存​​在,请告诉我。