MediaPlayer java.io.IOException: failed to execute command: status = 0x1 using Huawei ALE-L21

I got confused about a curious problem. My application allows the user to record a voice message that will be saved as an .amr file.

String fileName = getFilesDir().getAbsolutePath() + "/voiceMessage.amr";

MediaRecorder mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_WB);
mediaRecorder.setOutputFile(fileName);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);

After recording, the user can play back the recorded message, which works as expected:

MediaPlayer mediaPlayer = new MediaPlayer();

try {
    fileName = getFilesDir().getAbsolutePath() + "/voiceMessage.amr";
    Log.i(TAG, fileName);
    mediaPlayer.setDataSource(fileName);
    mediaPlayer.prepare();
    mediaPlayer.start();
} catch (IOException e) {
}

Logcat prints /data/data/com.messages.android/files/voiceMessage.amrfor fileName, which is good. After saving the voice message, I upload it to my server and upload it later for each user. The downloaded file is saved in the intermediate storage.

Now the part that throws the exception:

MediaPlayer mediaPlayer = new MediaPlayer();
File voiceMessage = user.getVoiceMessageFile(context);

if (voiceMessage.exists()) {
    try {
        Log.i(TAG, voiceMessage.getAbsolutePath());
        mediaPlayer.setDataSource(voiceMessage.getAbsolutePath());
        mediaPlayer.prepare();
        mediaPlayer.start();
    } catch (IOException e) {

    }
}

Logcat /data/data/com.messages.android/files/c02bfe404359860eb582aff318afb1f41469514396529.amr voiceMessage.getAbsolutePath(), . , . . .

- mediaPlayer.prepare():

> java.io.IOException: Prepare failed.: status=0x1  at
> android.media.MediaPlayer._prepare(Native Method)     at
> android.media.MediaPlayer.prepare(MediaPlayer.java:1168)  at
> com.messages.android.views.SeekBarLinearLayoutView.onClick(SeekBarLinearLayoutView.java:172)
>   at android.view.View.performClick(View.java:4766)   at
> android.view.View$PerformClick.run(View.java:19683)   at
> android.os.Handler.handleCallback(Handler.java:739)   at
> android.os.Handler.dispatchMessage(Handler.java:95)   at
> android.os.Looper.loop(Looper.java:135)   at
> android.app.ActivityThread.main(ActivityThread.java:5538)     at
> java.lang.reflect.Method.invoke(Native Method)    at
> java.lang.reflect.Method.invoke(Method.java:372)  at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
>   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

Huawei ALE-L21. Samsung Huawei .

: , .

1.

FileInputStream fi = new FileInputStream(voiceMessage);
mediaPlayer.setDataSource(fi.getFD());

2.

voiceMessage.setReadable(true, false);
mediaPlayer.setDataSource(voiceMessage.getAbsolutePath());

3: - : , , . , , . , OutputFormat , ? OutputFormat, Android 4.1+ ?

+4

Source: https://habr.com/ru/post/1649212/


All Articles