Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions RNSound/RNSound.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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];
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand All @@ -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];
Expand Down
6 changes: 3 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions sound.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down