File tree 6 files changed +29
-1
lines changed
android-exoplayer/src/main/java/com/brentvatne/exoplayer
6 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -239,6 +239,7 @@ var styles = StyleSheet.create({
239
239
* [ volume] ( #volume )
240
240
241
241
### Event props
242
+ * [ onAudioBecomingNoisy] ( #onaudiobecomingnoisy )
242
243
* [ onLoad] ( #onload )
243
244
* [ onLoadStart] ( #onloadstart )
244
245
* [ onProgress] ( #onprogress )
@@ -452,6 +453,13 @@ Platforms: all
452
453
453
454
### Event props
454
455
456
+ #### onAudioBecomingNoisy
457
+ 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.
458
+
459
+ Payload: none
460
+
461
+ Platforms: Android ExoPlayer, iOS
462
+
455
463
#### onLoad
456
464
Callback function that is called when the media is loaded and ready to play.
457
465
Original file line number Diff line number Diff line change @@ -235,6 +235,7 @@ export default class Video extends Component {
235
235
onVideoEnd : this . _onEnd ,
236
236
onVideoBuffer : this . _onBuffer ,
237
237
onTimedMetadata : this . _onTimedMetadata ,
238
+ onVideoAudioBecomingNoisy : this . _onAudioBecomingNoisy ,
238
239
onVideoFullscreenPlayerWillPresent : this . _onFullscreenPlayerWillPresent ,
239
240
onVideoFullscreenPlayerDidPresent : this . _onFullscreenPlayerDidPresent ,
240
241
onVideoFullscreenPlayerWillDismiss : this . _onFullscreenPlayerWillDismiss ,
@@ -296,6 +297,7 @@ Video.propTypes = {
296
297
onVideoSeek : PropTypes . func ,
297
298
onVideoEnd : PropTypes . func ,
298
299
onTimedMetadata : PropTypes . func ,
300
+ onVideoAudioBecomingNoisy : PropTypes . func ,
299
301
onVideoFullscreenPlayerWillPresent : PropTypes . func ,
300
302
onVideoFullscreenPlayerDidPresent : PropTypes . func ,
301
303
onVideoFullscreenPlayerWillDismiss : PropTypes . func ,
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ class VideoEventEmitter {
42
42
private static final String EVENT_BUFFER = "onVideoBuffer" ;
43
43
private static final String EVENT_IDLE = "onVideoIdle" ;
44
44
private static final String EVENT_TIMED_METADATA = "onTimedMetadata" ;
45
- private static final String EVENT_AUDIO_BECOMING_NOISY = "onAudioBecomingNoisy " ;
45
+ private static final String EVENT_AUDIO_BECOMING_NOISY = "onVideoAudioBecomingNoisy " ;
46
46
private static final String EVENT_AUDIO_FOCUS_CHANGE = "onAudioFocusChanged" ;
47
47
private static final String EVENT_PLAYBACK_RATE_CHANGE = "onPlaybackRateChange" ;
48
48
Original file line number Diff line number Diff line change 17
17
@property (nonatomic , copy ) RCTBubblingEventBlock onVideoSeek;
18
18
@property (nonatomic , copy ) RCTBubblingEventBlock onVideoEnd;
19
19
@property (nonatomic , copy ) RCTBubblingEventBlock onTimedMetadata;
20
+ @property (nonatomic , copy ) RCTBubblingEventBlock onVideoAudioBecomingNoisy;
20
21
@property (nonatomic , copy ) RCTBubblingEventBlock onVideoFullscreenPlayerWillPresent;
21
22
@property (nonatomic , copy ) RCTBubblingEventBlock onVideoFullscreenPlayerDidPresent;
22
23
@property (nonatomic , copy ) RCTBubblingEventBlock onVideoFullscreenPlayerWillDismiss;
Original file line number Diff line number Diff line change @@ -91,6 +91,11 @@ - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
91
91
selector: @selector (applicationWillEnterForeground: )
92
92
name: UIApplicationWillEnterForegroundNotification
93
93
object: nil ];
94
+
95
+ [[NSNotificationCenter defaultCenter ] addObserver: self
96
+ selector: @selector (audioRouteChanged: )
97
+ name: AVAudioSessionRouteChangeNotification
98
+ object: nil ];
94
99
}
95
100
96
101
return self;
@@ -190,6 +195,17 @@ - (void)applicationWillEnterForeground:(NSNotification *)notification
190
195
}
191
196
}
192
197
198
+ #pragma mark - Audio events
199
+
200
+ - (void )audioRouteChanged : (NSNotification *)notification
201
+ {
202
+ NSNumber *reason = [[notification userInfo ] objectForKey: AVAudioSessionRouteChangeReasonKey];
203
+ NSNumber *previousRoute = [[notification userInfo ] objectForKey: AVAudioSessionRouteChangePreviousRouteKey];
204
+ if (reason.unsignedIntValue == AVAudioSessionRouteChangeReasonOldDeviceUnavailable) {
205
+ self.onVideoAudioBecomingNoisy (@{@" target" : self.reactTag });
206
+ }
207
+ }
208
+
193
209
#pragma mark - Progress
194
210
195
211
- (void )sendProgressUpdate
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ - (dispatch_queue_t)methodQueue
46
46
RCT_EXPORT_VIEW_PROPERTY (onVideoSeek, RCTBubblingEventBlock);
47
47
RCT_EXPORT_VIEW_PROPERTY (onVideoEnd, RCTBubblingEventBlock);
48
48
RCT_EXPORT_VIEW_PROPERTY (onTimedMetadata, RCTBubblingEventBlock);
49
+ RCT_EXPORT_VIEW_PROPERTY (onVideoAudioBecomingNoisy, RCTBubblingEventBlock);
49
50
RCT_EXPORT_VIEW_PROPERTY (onVideoFullscreenPlayerWillPresent, RCTBubblingEventBlock);
50
51
RCT_EXPORT_VIEW_PROPERTY (onVideoFullscreenPlayerDidPresent, RCTBubblingEventBlock);
51
52
RCT_EXPORT_VIEW_PROPERTY (onVideoFullscreenPlayerWillDismiss, RCTBubblingEventBlock);
You can’t perform that action at this time.
0 commit comments