As the title describes, I'm having issues stopping audio playback with Titanium.Media.AudioPlayer on Android 11. I am using Titanium SDK 10.1.0.GA.
It works just fine on Android versions 8 and 10 (the only two other versions I've tested thus far).
If it helps, this is how I initialize my audioplayer (which is defined in Alloy.Globals):
Alloy.Globals.player = Ti.Media.createAudioPlayer({
url: audioPath,
allowBackground: true,
audioFocus: true,
audioType: Ti.Media.Sound.AUDIO_TYPE_MEDIA
});
Calling Alloy.Globals.player.stop(); does absolutely nothing. The audio just continues to play.
What should I be doing to get this to work on Android 11?
EDIT: Here is the output of my player, seems to not even be playing, which is odd:
[DEBUG] PLAYER: :{
[DEBUG] "volume": 1,
[DEBUG] "url": "file:///android_asset/Resources/audio/4.mp3",
[DEBUG] "muted": false,
[DEBUG] "time": 0,
[DEBUG] "audioSessionId": 0,
[DEBUG] "playing": false,
[DEBUG] "audioType": 0,
[DEBUG] "paused": false,
[DEBUG] "duration": 0,
[DEBUG] "apiName": "Ti.Media.AudioPlayer",
[DEBUG] "bubbleParent": true,
[DEBUG] "allowBackground": true,
[DEBUG] "audioFocus": true,
[DEBUG] "_events": {
[DEBUG] "complete": {}
[DEBUG] }
Working fine in Android 12 (Pixel 4, Titanium 10.1.1.GA).
alloy.js
index.js
And should also work in Android 11. Try to check if
Alloy.Globals.playeractually contains something and is not empty. Another thing you can test:so you can see if it works with a local media player and if it stops after 5 seconds.
It might also be good to use global backbone events and use that to start/stop the player. That should be better than having the whole audioplayer in the global space.