Variant of cordova-plugin-media with audio focus management.
cordova plugin add https://github.com/FmeuMan/cordova-plugin-media
- Android
- iOS
Request audio focus.
Media.requestFocus(options, successCallback);
- successCallback - function(boolean) : called when focus request is granted or refused. The boolean parameter will be set to true of false if focus is granted or not.
- options - {focusMode: string} :
- focusMode = 'gain': give full focus to the application, muting other apps (default mode on ios)
- focusMode = 'mix' : play the sounds while other apps can play sounds too (default mode on android)
- focusMode = 'duck' : lower volume of other apps
Release audio focus if any
Media.releaseFocus();
NOTE : Other app may not resume playing sounds depending on how their audio focus management if implemented. This is specialy true for full focus ('gain' focusMode).
Starts or resumes playing an audio file.
media.play(options);
- options - {focusMode: string, autoReleaseFocus: boolean} :
- focusMode : same as Media.requestFocus
- autoReleaseFocus : automaticaly release focus after media play
Focus is released on media.release()