issue 310 - Added a new property, ignoreSilentSwitch. (#403)
* issue 310 - Added a new property, ignoreSilentSwitch. When true, audio will play even when the silent switch on an iOS device is set to silent. When false, the audio will toggle with the silent switch. Sets the AVAudioSession to either playback or ambient. * Added ignoreSilentSwitch usage to example app and to readme * Changed ignoreSilentSwitch to accept two string values, ignore and obey. This accounts for the case where the user does not want to modify the audio session from a particular video instance. The user would not use the ignoreSilentSwitch property at all in that case. Also, the audio session will only be updated when the video is unpaused, instead of whenever the video component has updated props. This allows for multiple videos to be on the screen, with the most recent video unpaused (aka played) being the video that has control over the audio session.
This commit is contained in:
committed by
Matt Apperson
parent
c45f5f5b38
commit
98c51f114b
@@ -43,6 +43,7 @@ static NSString *const timedMetadata = @"timedMetadata";
|
||||
BOOL _playbackStalled;
|
||||
BOOL _playInBackground;
|
||||
BOOL _playWhenInactive;
|
||||
NSString * _ignoreSilentSwitch;
|
||||
NSString * _resizeMode;
|
||||
BOOL _fullscreenPlayerPresented;
|
||||
UIViewController * _presentingViewController;
|
||||
@@ -66,6 +67,7 @@ static NSString *const timedMetadata = @"timedMetadata";
|
||||
_playerBufferEmpty = YES;
|
||||
_playInBackground = false;
|
||||
_playWhenInactive = false;
|
||||
_ignoreSilentSwitch = @"inherit"; // inherit, ignore, obey
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(applicationWillResignActive:)
|
||||
@@ -118,7 +120,7 @@ static NSString *const timedMetadata = @"timedMetadata";
|
||||
{
|
||||
return [playerItem seekableTimeRanges].firstObject.CMTimeRangeValue;
|
||||
}
|
||||
|
||||
|
||||
return (kCMTimeRangeZero);
|
||||
}
|
||||
|
||||
@@ -376,7 +378,7 @@ static NSString *const timedMetadata = @"timedMetadata";
|
||||
} else
|
||||
orientation = @"portrait";
|
||||
}
|
||||
|
||||
|
||||
if(self.onVideoLoad) {
|
||||
self.onVideoLoad(@{@"duration": [NSNumber numberWithFloat:duration],
|
||||
@"currentTime": [NSNumber numberWithFloat:CMTimeGetSeconds(_playerItem.currentTime)],
|
||||
@@ -497,12 +499,23 @@ static NSString *const timedMetadata = @"timedMetadata";
|
||||
_playWhenInactive = playWhenInactive;
|
||||
}
|
||||
|
||||
- (void)setIgnoreSilentSwitch:(NSString *)ignoreSilentSwitch
|
||||
{
|
||||
_ignoreSilentSwitch = ignoreSilentSwitch;
|
||||
[self applyModifiers];
|
||||
}
|
||||
|
||||
- (void)setPaused:(BOOL)paused
|
||||
{
|
||||
if (paused) {
|
||||
[_player pause];
|
||||
[_player setRate:0.0];
|
||||
} else {
|
||||
if([_ignoreSilentSwitch isEqualToString:@"ignore"]) {
|
||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
|
||||
} else if([_ignoreSilentSwitch isEqualToString:@"obey"]) {
|
||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
|
||||
}
|
||||
[_player play];
|
||||
[_player setRate:_rate];
|
||||
}
|
||||
|
@@ -28,6 +28,7 @@ RCT_EXPORT_VIEW_PROPERTY(controls, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(volume, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(playInBackground, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(playWhenInactive, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(ignoreSilentSwitch, NSString);
|
||||
RCT_EXPORT_VIEW_PROPERTY(rate, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(seek, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(currentTime, float);
|
||||
|
Reference in New Issue
Block a user