Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2a46d4f

Browse files
authored
Merge pull request zmxv#3 from cark1/handle_duck_and_mix
Handle duck and mix
2 parents e65b220 + 7312617 commit 2a46d4f

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

‎RNSound/RNSound.m‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ - (NSDictionary *)constantsToExport {
147147
}
148148

149149
RCT_EXPORT_METHOD(setCategory
150-
: (NSString *)categoryName mixWithOthers
151-
: (BOOL)mixWithOthers) {
150+
: (NSString *)categoryName duckAudio
151+
: (BOOL)duckAudio) {
152152
AVAudioSession *session = [AVAudioSession sharedInstance];
153153
NSString *category = nil;
154154

@@ -173,13 +173,15 @@ - (NSDictionary *)constantsToExport {
173173
}
174174

175175
if (category) {
176-
if (mixWithOthers) {
176+
if (duckAudio) {
177177
[session setCategory:category
178178
withOptions:AVAudioSessionCategoryOptionDuckOthers
179179
//| AVAudioSessionCategoryOptionAllowBluetooth
180180
error:nil];
181181
} else {
182-
[session setCategory:category error:nil];
182+
[session setCategory:category
183+
withOptions:AVAudioSessionCategoryOptionMixWithOthers
184+
error:nil];
183185
}
184186
}
185187
}

‎android/src/main/java/com/zmxv/RNSound/RNSoundModule.java‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class RNSoundModule extends ReactContextBaseJavaModule implements AudioMa
3131
ReactApplicationContext context;
3232
final static Object NULL = null;
3333
String category;
34-
Boolean mixWithOthers = true;
34+
Boolean duckAudio = true;
3535
Double focusedPlayerKey;
3636
Boolean wasPlayingBeforeFocusChange = false;
3737

@@ -236,10 +236,10 @@ public void play(final Double key, final Callback callback) {
236236
}
237237

238238
// Request audio focus in Android system
239-
if (!this.mixWithOthers) {
239+
if (!this.duckAudio) {
240240
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
241241

242-
audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
242+
audioManager.abandonAudioFocus(this);
243243

244244
this.focusedPlayerKey = key;
245245
}else {
@@ -308,7 +308,7 @@ public void stop(final Double key, final Callback callback) {
308308
}
309309

310310
// Release audio focus in Android system
311-
if (!this.mixWithOthers && key == this.focusedPlayerKey) {
311+
if (!this.duckAudio && key == this.focusedPlayerKey) {
312312
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
313313
audioManager.abandonAudioFocus(this);
314314
}
@@ -333,7 +333,7 @@ public void release(final Double key) {
333333
this.playerPool.remove(key);
334334

335335
// Release audio focus in Android system
336-
if (!this.mixWithOthers && key == this.focusedPlayerKey) {
336+
if (!this.duckAudio && key == this.focusedPlayerKey) {
337337
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
338338
audioManager.abandonAudioFocus(this);
339339
}
@@ -452,11 +452,11 @@ public void setSpeakerphoneOn(final Double key, final Boolean speaker) {
452452
}
453453

454454
@ReactMethod
455-
public void setCategory(final String category, final Boolean mixWithOthers) {
455+
public void setCategory(final String category, final Boolean duckAudio) {
456456
this.category = category;
457-
this.mixWithOthers = mixWithOthers;
457+
this.duckAudio = duckAudio;
458458

459-
if(!this.mixWithOthers){
459+
if(!this.duckAudio){
460460
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
461461
audioManager.abandonAudioFocus(this);
462462
}
@@ -465,7 +465,7 @@ public void setCategory(final String category, final Boolean mixWithOthers) {
465465

466466
@Override
467467
public void onAudioFocusChange(int focusChange) {
468-
if (!this.mixWithOthers) {
468+
if (!this.duckAudio) {
469469
MediaPlayer player = this.playerPool.get(this.focusedPlayerKey);
470470

471471
if (player != null) {

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-sound",
3-
"version": "0.11.5",
3+
"version": "0.11.6",
44
"description": "React Native module for playing sound clips on iOS, Android, and Windows",
55
"main": "sound.js",
66
"typings": "index.d.ts",

‎sound.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,9 @@ Sound.setActive = function(value) {
307307
}
308308
};
309309

310-
Sound.setCategory = function(value, mixWithOthers = false) {
310+
Sound.setCategory = function(value, duckAudio = false) {
311311
if (!IsWindows) {
312-
RNSound.setCategory(value, mixWithOthers);
312+
RNSound.setCategory(value, duckAudio);
313313
}
314314
};
315315

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /