A Cordova plugin for iOS to expose AVAudioSession setCategory:error:
Once you have set up your Cordova project, run:
cordova plugin add --save https://github.com/msbit/cordova-plugin-audio-category.git
and then, in your code:
window.MSBAudioCategory.setCategory('soloAmbient');
The category value specified can be as follows:
ambient
corresponding toAVAudioSessionCategoryAmbient
multiRoute
corresponding toAVAudioSessionCategoryMultiRoute
playAndRecord
corresponding toAVAudioSessionCategoryPlayAndRecord
playback
corresponding toAVAudioSessionCategoryPlayback
record
corresponding toAVAudioSessionCategoryRecord
soloAmbient
corresponding toAVAudioSessionCategorySoloAmbient
Details of the individual AVAudioSessionCategory
behaviours can be found in the Apple developer documentation.
Methods available in the plugin are:
getCategory()
setCategory(name)
window.MSBAudioCategory.getCategory().then((category) => {
console.log(`Current AVAudioSessionCategory is ${category}`);
});
window.MSBAudioCategory.setCategory('playback').then((result) => {
console.log(`AVAudioSessionCategory has been updated: ${result}`);
}).catch((error) => {
console.log(`AVAudioSessionCategory could not be updated: ${error}`);
});