apache / apache/cordova-plugin-media

MediaError.MEDIA_ERR_ABORTED Playing recorded audio on Android Sdk <= 21

Open
#245 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
391
Forks
762
PR merge metrics
No merged PRs in 30d

Description

# Bug Report

## Problem

Playing audio on Android Sdk <= 21 after recording from this plugin doesn't work. We play the audio and receive a `MediaError.MEDIA_ERR_ABORTED` just after the state changes from `Media.MEDIA_STARTING` to `Media.MEDIA_RUNNING`.

If we are on a Android Sdk >= 21 device, everything works fine.

### What is expected to happen?

We expected the audio recorded from cordova-plugin-media on Android can be played on Sdk <= 21.

### What does actually happen?

After recording audio on a device with Android Sdk <= 21, when playing the audio recorded, the following error occurs:

`07-30 09:13:27.302 7116-7132/ E/MediaPlayer: error (1, -38)`

It's happening because a change in the following lines:

https://github.com/apache/cordova-plugin-media/blob/master/src/android/AudioPlayer.java#L156
https://github.com/apache/cordova-plugin-media/blob/master/src/android/AudioPlayer.java#L157

This change was proposed by this CB-12319: https://github.com/apache/cordova-plugin-media/pull/124

If we change the lines 156 and 157 back to the original state, everything works:

```
this.recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR); // RAW_AMR);
this.recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
```

The CB-12319 seems to fix bug that recorded audio files of Android cannot be played in iOS with the html tag. If we change back to the previous state, we cannot play audio on iOS with the html tag.

## Information

To reproduce the problem, just run the following app on Android emulator Sdk 21: https://github.com/jordanorc/SoundRecorder.

Changing the lines 156 and 157 back to original state, makes the playing works again.

### Command or Code

```
1. git clone https://github.com/jordanorc/SoundRecorder
2. npm i
3. cordova prepare android
4. cordova run android
5. Click on button "Record Sound"
6. Click on button "Stop Recording"
7. Click on button "Playback"
```

It show works as expected on Android Sdk > 21 and should show a log error message on Android Sdk <= 21.

### Environment, Platform, Device

Android Sdk <= 21

### Version information

```
cordova-lib@9.0.1 with:
cordova-common@3.1.0
cordova-create@2.0.0
cordova-fetch@2.0.1
cordova-serve@3.0.0

Environment:
OS: linux
Node: v8.11.4
npm: 6.5.0

Plugins:
cordova-plugin-device
cordova-plugin-file
cordova-plugin-media
cordova-plugin-splashscreen
cordova-plugin-whitelist
```

## Checklist

- [X] I searched for existing GitHub issues
- [X] I updated all Cordova tooling to most recent version
- [X] I included all the necessary information above

Contributor guide

Open the contributing guide

Research direction

Start with src/android/AudioPlayer.java around lines 156-157 and compare the change from CB-12319, then reproduce the failure using the linked SoundRecorder app on Android SDK <=21. Check playback after recording against the existing behavior on newer Android and iOS HTML audio. Done means recorded audio plays on older Android without regressing the cross-platform playback behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
audio-video-rtc, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.