diff --git a/RNSound/RNSound.m b/RNSound/RNSound.m index df3784e4..c2ab2223 100644 --- a/RNSound/RNSound.m +++ b/RNSound/RNSound.m @@ -148,7 +148,8 @@ - (NSDictionary *)constantsToExport { RCT_EXPORT_METHOD(setCategory : (NSString *)categoryName mixWithOthers - : (BOOL)mixWithOthers) { + : (BOOL)mixWithOthers + : (BOOL)duckOthers) { AVAudioSession *session = [AVAudioSession sharedInstance]; NSString *category = nil; @@ -174,16 +175,23 @@ - (NSDictionary *)constantsToExport { if (category) { if (mixWithOthers) { - [session setCategory:category - withOptions:AVAudioSessionCategoryOptionMixWithOthers | - AVAudioSessionCategoryOptionAllowBluetooth - error:nil]; + if (duckOthers) { + [session setCategory:category + withOptions:AVAudioSessionCategoryOptionDuckOthers + error:nil]; + } else { + [session setCategory:category + withOptions:AVAudioSessionCategoryOptionMixWithOthers | + AVAudioSessionCategoryOptionAllowBluetooth + error:nil]; + } } else { [session setCategory:category error:nil]; } } } + RCT_EXPORT_METHOD(enableInSilenceMode : (BOOL)enabled) { AVAudioSession *session = [AVAudioSession sharedInstance]; [session setCategory:AVAudioSessionCategoryPlayback error:nil]; @@ -258,6 +266,7 @@ - (NSDictionary *)constantsToExport { RCT_EXPORT_METHOD(pause : (nonnull NSNumber *)key withCallback : (RCTResponseSenderBlock)callback) { + [[AVAudioSession sharedInstance] setActive:NO error:nil]; AVAudioPlayer *player = [self playerForKey:key]; if (player) { [player pause]; @@ -268,6 +277,7 @@ - (NSDictionary *)constantsToExport { RCT_EXPORT_METHOD(stop : (nonnull NSNumber *)key withCallback : (RCTResponseSenderBlock)callback) { + [[AVAudioSession sharedInstance] setActive:NO error:nil]; AVAudioPlayer *player = [self playerForKey:key]; if (player) { [player stop]; @@ -278,6 +288,7 @@ - (NSDictionary *)constantsToExport { RCT_EXPORT_METHOD(release : (nonnull NSNumber *)key) { @synchronized(self) { + [[AVAudioSession sharedInstance] setActive:NO error:nil]; AVAudioPlayer *player = [self playerForKey:key]; if (player) { [player stop]; diff --git a/index.d.ts b/index.d.ts index 27a810d2..5005484c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -26,8 +26,7 @@ declare class Sound { * Use this method to deactivate the AVAudioSession when playback is finished in order for other apps * to regain access to the audio stack. * - * @param category AVAudioSession category - * @param mixWithOthers Can be set to true to force mixing with other audio sessions. + * @param active AVAudioSession setActive */ static setActive(active: boolean): void @@ -38,8 +37,9 @@ declare class Sound { * * @param category AVAudioSession category * @param mixWithOthers Can be set to true to force mixing with other audio sessions. + * @param duckOthers Can be set to true to duck other sounds (iOS). */ - static setCategory(category: AVAudioSessionCategory, mixWithOthers?: boolean): void + static setCategory(category: AVAudioSessionCategory, mixWithOthers?: boolean, duckOthers?: boolean): void /** * Sets AVAudioSession mode, which works in conjunction with the category to determine audio mixing behavior. diff --git a/sound.js b/sound.js index 33e61572..de4645f3 100644 --- a/sound.js +++ b/sound.js @@ -307,9 +307,9 @@ Sound.setActive = function(value) { } }; -Sound.setCategory = function(value, mixWithOthers = false) { +Sound.setCategory = function(value, mixWithOthers = false, duckOthers = false) { if (!IsWindows) { - RNSound.setCategory(value, mixWithOthers); + RNSound.setCategory(value, mixWithOthers, duckOthers); } };