apache / apache/cordova-plugin-media
Audio not playing sometimes
- Dominant language
- JavaScript
- Stars
- 391
- Forks
- 762
- PR merge metrics
- No merged PRs in 30d
Description
# Bug Report
## Problem
Sound doesn't play even when there's no error
### What is expected to happen?
The sound comes out from the device as expected when I play the audio object.
### What does actually happen?
I have 2 test devices, and on one of them the sound plays but on the other it was playing earlier today but has stopped playing now. The sound doesn't play even though the volume is set to 1.0 and the status callback shows the status as going from 1 to 2 then to 4.
## Information
This may sound similar to [this issue](https://github.com/apache/cordova-plugin-media/issues/277) but I'm not getting the `abort` error that's reported there.
### Command or Code
This is the code I use to play media:
```
export function playNewMsgAudio(isSend = false) {
const audioObj = new Media(
`${cordova.file.applicationDirectory}www/audio/${
isSend ? 'send' : 'recv'
}-msg.mp3`,
() => {},
error =>
logError(
'failed to initialize audio object for sent message',
{ error }
),
status => {
switch (status) {
case Media.MEDIA_PAUSED:
case Media.MEDIA_STOPPED:
audioObj.release();
break;
default:
break;
}
}
);
audioObj.play();
audioObj.setVolume('1.0');
}
```
### Environment, Platform, Device
Samsung Note 20 Ultra running Android 11, Tekno Pop2 Plus running Android 8.
### Version information
Cordova Android 10.1.1, cordova cli 10
## 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
Research direction
Start from the playNewMsgAudio function in the issue and reproduce the silent playback on the Samsung Note 20 Ultra and Tekno Pop2 Plus. Compare the Media status callbacks and volume behavior across Android 11 and Android 8, then document a reproducible cause and verify that audio plays reliably without errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, javascript
- Domain
- audio-video-rtc, mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100