我想播放存储在外部目录中的 wav 文件,但我无法创建 MediaPlayer 实例

I want to play wav file stored in external directory but I am not able to create MediaPlayer instance

我正在编写一个使用麦克风创建 wav 文件的小应用程序。我正在使用 AudioRecord class 获取原始数据,然后将其以 wav 格式保存在外部存储器中。问题是我无法创建 MediaPlayer 实例来保存 wav 文件。我能够打开选定的文件并且我有读取它的权限。 Wav 文件已正确保存(至少我猜是这样,因为我可以在计算机上播放)。如果有任何帮助,我将不胜感激:)

到目前为止我得到了什么:

@Override
public void onRecordingClick(int position) {
    if (player == null) {
        String path = wavFilepathList.get(position);
        File audioFile = new File(path);

        Log.d("audioFileLog", "File exists: " + audioFile.exists() + ", can read: " + audioFile.canRead());

        player = new MediaPlayer();
        try {
            player.setDataSource(path);
            Log.d("audioFileLog", "Data Source Changed");
            player.setOnPreparedListener(this);
            Log.d("audioFileLog", "Listener Set, before prepare method");
            player.prepareAsync();
            Log.d("audioFileLog", "after prepare method");
        } catch (IOException e) {
            e.printStackTrace();
            Log.d("audioFileLog", "IOException when setting data source");
        }
    }
}

@Override
public void onPrepared(MediaPlayer mp) {
    mp.start();
    Log.d("audioFileLog", "after played method");
}

Logcat:

D/audioFileLog: File exists: true, can read: true
E/ExtMediaPlayer-JNI: env->IsInstanceOf fails
E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
E/ExtMediaPlayer-JNI: env->IsInstanceOf fails
E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
D/audioFileLog: Data Source Changed
D/audioFileLog: Listener Set, before prepare method
D/audioFileLog: after prepare method
E/MediaPlayer: error (1, -2147483648)
E/MediaPlayer: Error (1,-2147483648)

较早的实验:
1)

public void onRecordingClick(int position) {
    if (player == null) {

        File selectedFile = new File(wavFilepathList.get(position));

        Log.d("Main", "voice exists : " + selectedFile.exists() +
                ", can read : " + selectedFile.canRead());
        player = MediaPlayer.create(this, Uri.fromFile(selectedFile));
    }
    player.start();
} // on recording clicked

Logcat:

D/Main: voice exists : true, can read : true  
E/ExtMediaPlayer-JNI: env->IsInstanceOf fails  
E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0  
E/ExtMediaPlayer-JNI: env->IsInstanceOf fails  
E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0  
E/MediaPlayer: error (1, -2147483648)  
D/MediaPlayer: create failed:  

2)

@Override
public void onRecordingClick(int position) {
    if (player == null) {

        player= new MediaPlayer();
        try {
            player.setDataSource(wavFilepathList.get(position));

            player.setOnPreparedListener(this);
            player.prepareAsync();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
} // on recording clicked

@Override
public void onPrepared(MediaPlayer mp) {
    player.start();
}

Logcat:

E/ExtMediaPlayer-JNI: env->IsInstanceOf fails
E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
E/ExtMediaPlayer-JNI: env->IsInstanceOf fails
E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
E/MediaPlayer: error (1, -2147483648)
E/MediaPlayer: Error (1,-2147483648)  

尝试使用以下方式设置 mediaPlayer:

    try{
        File audioFile = new File("The File's Path");     //  audio.wav path
        if(audioFile.exists()){    
            Log.d("audioFileLog", "Found the file");
            MediaPlayer mp = new MediaPlayer();
            mp.setDataSource('audioFile.getPath());
            mp.prepare();
            mp.start();
        }else{
            Log.d("audioFileLog", "Did not find the file");
        }
    }catch(Exception ex){
        Log.d("audioFileLog", ex.toString());
    }

然后使用:

mp.stop();
mp.release();

完成后。

文件补丁不正确,因此出现问题...