Add onAudioBecomingNoisy for iOS

This commit is contained in:
Hampton Maxwell 2018-07-12 21:48:58 -07:00
parent 5178601edb
commit d003c87b57
4 changed files with 27 additions and 0 deletions

View File

@ -239,6 +239,7 @@ var styles = StyleSheet.create({
* [volume](#volume) * [volume](#volume)
### Event props ### Event props
* [onAudioBecomingNoisy](#onaudiobecomingnoisy)
* [onLoad](#onload) * [onLoad](#onload)
* [onLoadStart](#onloadstart) * [onLoadStart](#onloadstart)
* [onProgress](#onprogress) * [onProgress](#onprogress)
@ -452,6 +453,13 @@ Platforms: all
### Event props ### Event props
#### onAudioBecomingNoisy
Callback function that is called when the audio is about to become 'noisy' due to a change in audio outputs. Typically this is called when audio output is being switched from an external source like headphones back to the internal speaker. It's a good idea to pause the media when this happens so the speaker doesn't start blasting sound.
Payload: none
Platforms: Android ExoPlayer, iOS
#### onLoad #### onLoad
Callback function that is called when the media is loaded and ready to play. Callback function that is called when the media is loaded and ready to play.

View File

@ -235,6 +235,7 @@ export default class Video extends Component {
onVideoEnd: this._onEnd, onVideoEnd: this._onEnd,
onVideoBuffer: this._onBuffer, onVideoBuffer: this._onBuffer,
onTimedMetadata: this._onTimedMetadata, onTimedMetadata: this._onTimedMetadata,
onVideoAudioBecomingNoisy: this._onAudioBecomingNoisy,
onVideoFullscreenPlayerWillPresent: this._onFullscreenPlayerWillPresent, onVideoFullscreenPlayerWillPresent: this._onFullscreenPlayerWillPresent,
onVideoFullscreenPlayerDidPresent: this._onFullscreenPlayerDidPresent, onVideoFullscreenPlayerDidPresent: this._onFullscreenPlayerDidPresent,
onVideoFullscreenPlayerWillDismiss: this._onFullscreenPlayerWillDismiss, onVideoFullscreenPlayerWillDismiss: this._onFullscreenPlayerWillDismiss,
@ -296,6 +297,7 @@ Video.propTypes = {
onVideoSeek: PropTypes.func, onVideoSeek: PropTypes.func,
onVideoEnd: PropTypes.func, onVideoEnd: PropTypes.func,
onTimedMetadata: PropTypes.func, onTimedMetadata: PropTypes.func,
onVideoAudioBecomingNoisy: PropTypes.func,
onVideoFullscreenPlayerWillPresent: PropTypes.func, onVideoFullscreenPlayerWillPresent: PropTypes.func,
onVideoFullscreenPlayerDidPresent: PropTypes.func, onVideoFullscreenPlayerDidPresent: PropTypes.func,
onVideoFullscreenPlayerWillDismiss: PropTypes.func, onVideoFullscreenPlayerWillDismiss: PropTypes.func,

View File

@ -91,6 +91,11 @@ static NSString *const timedMetadata = @"timedMetadata";
selector:@selector(applicationWillEnterForeground:) selector:@selector(applicationWillEnterForeground:)
name:UIApplicationWillEnterForegroundNotification name:UIApplicationWillEnterForegroundNotification
object:nil]; object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(audioRouteChanged:)
name:AVAudioSessionRouteChangeNotification
object:nil];
} }
return self; return self;
@ -190,6 +195,17 @@ static NSString *const timedMetadata = @"timedMetadata";
} }
} }
#pragma mark - Audio events
- (void)audioRouteChanged:(NSNotification *)notification
{
NSNumber *reason = [[notification userInfo] objectForKey:AVAudioSessionRouteChangeReasonKey];
NSNumber *previousRoute = [[notification userInfo] objectForKey:AVAudioSessionRouteChangePreviousRouteKey];
if (reason.unsignedIntValue == AVAudioSessionRouteChangeReasonOldDeviceUnavailable) {
self.onVideoAudioBecomingNoisy(@{@"target": self.reactTag});
}
}
#pragma mark - Progress #pragma mark - Progress
- (void)sendProgressUpdate - (void)sendProgressUpdate

View File

@ -46,6 +46,7 @@ RCT_EXPORT_VIEW_PROPERTY(onVideoProgress, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onVideoSeek, RCTBubblingEventBlock); RCT_EXPORT_VIEW_PROPERTY(onVideoSeek, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onVideoEnd, RCTBubblingEventBlock); RCT_EXPORT_VIEW_PROPERTY(onVideoEnd, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onTimedMetadata, RCTBubblingEventBlock); RCT_EXPORT_VIEW_PROPERTY(onTimedMetadata, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onVideoAudioBecomingNoisy, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onVideoFullscreenPlayerWillPresent, RCTBubblingEventBlock); RCT_EXPORT_VIEW_PROPERTY(onVideoFullscreenPlayerWillPresent, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onVideoFullscreenPlayerDidPresent, RCTBubblingEventBlock); RCT_EXPORT_VIEW_PROPERTY(onVideoFullscreenPlayerDidPresent, RCTBubblingEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onVideoFullscreenPlayerWillDismiss, RCTBubblingEventBlock); RCT_EXPORT_VIEW_PROPERTY(onVideoFullscreenPlayerWillDismiss, RCTBubblingEventBlock);