Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved ignored silent switch in iOS when player is set to paused #2215

Merged
merged 3 commits into from
Sep 9, 2021
Merged
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
69 changes: 42 additions & 27 deletions ios/Video/RCTVideo.m
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ - (void)setupPipController {
- (void)setIgnoreSilentSwitch:(NSString *)ignoreSilentSwitch
{
_ignoreSilentSwitch = ignoreSilentSwitch;
[self configureAudio];
[self applyModifiers];
}

Expand All @@ -930,29 +931,8 @@ - (void)setPaused:(BOOL)paused
[_player pause];
[_player setRate:0.0];
} else {
AVAudioSession *session = [AVAudioSession sharedInstance];
AVAudioSessionCategory category = nil;
AVAudioSessionCategoryOptions options = nil;

if([_ignoreSilentSwitch isEqualToString:@"ignore"]) {
category = AVAudioSessionCategoryPlayback;
} else if([_ignoreSilentSwitch isEqualToString:@"obey"]) {
category = AVAudioSessionCategoryAmbient;
}

if([_mixWithOthers isEqualToString:@"mix"]) {
options = AVAudioSessionCategoryOptionMixWithOthers;
} else if([_mixWithOthers isEqualToString:@"duck"]) {
options = AVAudioSessionCategoryOptionDuckOthers;
}

if (category != nil && options != nil) {
[session setCategory:category withOptions:options error:nil];
} else if (category != nil && options == nil) {
[session setCategory:category error:nil];
} else if (category == nil && options != nil) {
[session setCategory:session.category withOptions:options error:nil];
}
[self configureAudio];

if (@available(iOS 10.0, *) && !_automaticallyWaitsToMinimizeStalling) {
[_player playImmediatelyAtRate:_rate];
Expand Down Expand Up @@ -1086,6 +1066,33 @@ - (void)applyModifiers
[self setAllowsExternalPlayback:_allowsExternalPlayback];
}

- (void)configureAudio
{
AVAudioSession *session = [AVAudioSession sharedInstance];
AVAudioSessionCategory category = nil;
AVAudioSessionCategoryOptions options = nil;

if([_ignoreSilentSwitch isEqualToString:@"ignore"]) {
category = AVAudioSessionCategoryPlayback;
} else if([_ignoreSilentSwitch isEqualToString:@"obey"]) {
category = AVAudioSessionCategoryAmbient;
}

if([_mixWithOthers isEqualToString:@"mix"]) {
options = AVAudioSessionCategoryOptionMixWithOthers;
} else if([_mixWithOthers isEqualToString:@"duck"]) {
options = AVAudioSessionCategoryOptionDuckOthers;
}

if (category != nil && options != nil) {
[session setCategory:category withOptions:options error:nil];
} else if (category != nil && options == nil) {
[session setCategory:category error:nil];
} else if (category == nil && options != nil) {
[session setCategory:session.category withOptions:options error:nil];
}
}

- (void)setRepeat:(BOOL)repeat {
_repeat = repeat;
}
Expand Down Expand Up @@ -1127,12 +1134,20 @@ - (void)setMediaSelectionTrackForCharacteristic:(AVMediaCharacteristic)character
}
}
} else { // default. invalid type or "system"
[_player.currentItem selectMediaOptionAutomaticallyInMediaSelectionGroup:group];
return;
#if TARGET_OS_TV
// Do noting. Fix for tvOS native audio menu language selector
#else
[_player.currentItem selectMediaOptionAutomaticallyInMediaSelectionGroup:group];
return;
#endif
}

// If a match isn't found, option will be nil and text tracks will be disabled
[_player.currentItem selectMediaOption:mediaOption inMediaSelectionGroup:group];

#if TARGET_OS_TV
// Do noting. Fix for tvOS native audio menu language selector
#else
// If a match isn't found, option will be nil and text tracks will be disabled
[_player.currentItem selectMediaOption:mediaOption inMediaSelectionGroup:group];
#endif
}

- (void)setSelectedAudioTrack:(NSDictionary *)selectedAudioTrack {
Expand Down