From d8935c434291ce3de22b669485d7464bf4b0f178 Mon Sep 17 00:00:00 2001 From: David Cornejo Date: Tue, 14 Jan 2025 23:48:02 -0600 Subject: [PATCH 1/3] Add missing autoplay prop type --- index.d.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.d.ts b/index.d.ts index 68bd59ee..d8218e6f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -231,6 +231,13 @@ export type VLCPlayerProps = VLCPlayerCallbackProps & { * React native view stylesheet styles */ style?: StyleProp; + + /** + * Enables autoplay + * + * @default true + */ + autoplay?: boolean; }; /** From b78cf2f0bcd3b59efcce97c66c0c725636bab95d Mon Sep 17 00:00:00 2001 From: David Cornejo Date: Tue, 14 Jan 2025 23:48:26 -0600 Subject: [PATCH 2/3] Add missing autoplay player prop --- VLCPlayer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/VLCPlayer.js b/VLCPlayer.js index 146458cc..5d3d9a10 100755 --- a/VLCPlayer.js +++ b/VLCPlayer.js @@ -212,6 +212,7 @@ VLCPlayer.propTypes = { /* Wrapper component */ source: PropTypes.oneOfType([PropTypes.object, PropTypes.number]), subtitleUri: PropTypes.string, + autoplay: PropTypes.bool, onError: PropTypes.func, onProgress: PropTypes.func, From c2a9ae99eab519d008e9509b6a203c3b624c23d7 Mon Sep 17 00:00:00 2001 From: David Cornejo Date: Tue, 14 Jan 2025 23:49:21 -0600 Subject: [PATCH 3/3] Add autoplay player support --- ios/RCTVLCPlayer/RCTVLCPlayer.m | 86 ++++++++------------------ ios/RCTVLCPlayer/RCTVLCPlayerManager.m | 1 + 2 files changed, 28 insertions(+), 59 deletions(-) diff --git a/ios/RCTVLCPlayer/RCTVLCPlayer.m b/ios/RCTVLCPlayer/RCTVLCPlayer.m index f05024da..6cd073b0 100755 --- a/ios/RCTVLCPlayer/RCTVLCPlayer.m +++ b/ios/RCTVLCPlayer/RCTVLCPlayer.m @@ -34,7 +34,7 @@ @implementation RCTVLCPlayer NSString * _subtitleUri; NSDictionary * _videoInfo; - + BOOL _autoplay; } - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher @@ -75,6 +75,11 @@ - (void)applyModifiers [self play]; } +- (void)setAutoplay:(BOOL)autoplay +{ + _autoplay = autoplay; +} + - (void)setPaused:(BOOL)paused { if(_player){ @@ -97,67 +102,28 @@ -(void)play } } --(void)setResume:(BOOL)autoplay -{ - if(_player){ - [self _release]; - } - // [bavv edit start] - NSString* uri = [_source objectForKey:@"uri"]; - NSURL* _uri = [NSURL URLWithString:uri]; - NSDictionary* initOptions = [_source objectForKey:@"initOptions"]; - - _player = [[VLCMediaPlayer alloc] init]; - // [bavv edit end] - - [_player setDrawable:self]; - _player.delegate = self; - _player.scaleFactor = 0; - VLCMedia *media = [VLCMedia mediaWithURL:_uri]; - - for (NSString* option in initOptions) { - [media addOption:[option stringByReplacingOccurrencesOfString:@"--" withString:@""]]; - } - - _player.media = media; - _player.media.delegate = self; - [[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil]; - NSLog(@"autoplay: %i",autoplay); - self.onVideoLoadStart(@{ - @"target": self.reactTag - }); - -} - -(void)setSource:(NSDictionary *)source { - if(_player){ - [self _release]; - } _source = source; _videoInfo = nil; // [bavv edit start] - NSString* uri = [source objectForKey:@"uri"]; - BOOL autoplay = [RCTConvert BOOL:[source objectForKey:@"autoplay"]]; + NSString* uri = [_source objectForKey:@"uri"]; NSURL* _uri = [NSURL URLWithString:uri]; - NSDictionary* initOptions = [source objectForKey:@"initOptions"]; - - _player = [[VLCMediaPlayer alloc] init]; - // [bavv edit end] - - [_player setDrawable:self]; - _player.delegate = self; - _player.scaleFactor = 0; - - VLCMedia *media = [VLCMedia mediaWithURL:_uri]; + int initType = [_source objectForKey:@"initType"]; + NSDictionary* initOptions = [_source objectForKey:@"initOptions"]; - for (NSString* option in initOptions) { - [media addOption:[option stringByReplacingOccurrencesOfString:@"--" withString:@""]]; + if(initType == 1) { + _player = [[VLCMediaPlayer alloc] init]; + }else { + _player = [[VLCMediaPlayer alloc] initWithOptions:initOptions]; } + _player.delegate = self; + _player.drawable = self; + // [bavv edit end] - _player.media = media; - _player.media.delegate = self; + _player.media = [VLCMedia mediaWithURL:_uri]; + [[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil]; NSLog(@"autoplay: %i",autoplay); self.onVideoLoadStart(@{ @@ -167,8 +133,8 @@ -(void)setSource:(NSDictionary *)source [_player addPlaybackSlave:_subtitleUri type:VLCMediaPlaybackSlaveTypeSubtitle enforce:YES]; } -// if(autoplay) - [self play]; + if(_autoplay) + [_player play]; } - (void)setSubtitleUri:(NSString *)subtitleUri @@ -389,13 +355,15 @@ - (void)setMuted:(BOOL)value - (void)_release { - if(_player){ - [_player pause]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; + + if(_player.media) [_player stop]; + + if (_player) _player = nil; - _eventDispatcher = nil; - [[NSNotificationCenter defaultCenter] removeObserver:self]; - } + + _eventDispatcher = nil; } diff --git a/ios/RCTVLCPlayer/RCTVLCPlayerManager.m b/ios/RCTVLCPlayer/RCTVLCPlayerManager.m index f376be90..8003d648 100755 --- a/ios/RCTVLCPlayer/RCTVLCPlayerManager.m +++ b/ios/RCTVLCPlayer/RCTVLCPlayerManager.m @@ -45,5 +45,6 @@ - (dispatch_queue_t)methodQueue }; RCT_EXPORT_VIEW_PROPERTY(audioTrack, int); RCT_EXPORT_VIEW_PROPERTY(textTrack, int); +RCT_EXPORT_VIEW_PROPERTY(autoplay, BOOL); @end