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

24i ios track fullscreen controls #6

Open
wants to merge 3 commits into
base: feature/ios-track-fullscreen-controls
Choose a base branch
from
Open
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions examples/embed-and-fullscreen/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,35 @@ export default class VideoPlayer extends Component {
source={require('./broadchurch.mp4')}
style={{width: this.state.orientationWidth, height: this.state.orientationHeight }}
controls={true}
onLoad={() => { console.log('log: onload'); } }

onFullscreenPlayerWillPresent={ this.videoPlayerWillPresent }
onFullscreenPlayerDidPresent={ this.videoPlayerDidPresent }
onFullscreenPlayerWillDismiss={ this.videoPlayerWillDismiss }
onFullscreenPlayerDidDismiss={ this.videoPlayerDidDismiss }

onEnd={() => { console.log('log: onEnd'); }}
/>
<Button title="full screen" onPress={ this.onPress.bind(this) }></Button>
</View>
}

videoPlayerWillPresent() {
console.log('log: will present');
}

videoPlayerDidPresent() {
console.log('log: did present');
}

videoPlayerWillDismiss() {
console.log('log: will dismiss');
}

videoPlayerDidDismiss() {
console.log('log: did dismiss');
}

onPress() {
if (this.videoPlayer!=null)
this.videoPlayer.presentFullscreenPlayer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -1028,6 +1029,7 @@
DEAD_CODE_STRIPPING = NO;
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = VideoPlayer/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_LDFLAGS = (
"$(inherited)",
Expand All @@ -1047,6 +1049,7 @@
CURRENT_PROJECT_VERSION = 1;
HEADER_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = VideoPlayer/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_LDFLAGS = (
"$(inherited)",
Expand Down
7 changes: 7 additions & 0 deletions ios/RCTVideo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
D1107C0F2110259000073188 /* RCTVideoManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D1107C062110259000073188 /* RCTVideoManager.m */; };
D1107C102110259000073188 /* RCTVideoPlayerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D1107C082110259000073188 /* RCTVideoPlayerViewController.m */; };
D1107C112110259000073188 /* RCTVideoPlayerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D1107C082110259000073188 /* RCTVideoPlayerViewController.m */; };
FA5A7A5B2270E5870086953B /* AVPlayerViewController+Fullscreen.m in Sources */ = {isa = PBXBuildFile; fileRef = FA5A7A5A2270E5870086953B /* AVPlayerViewController+Fullscreen.m */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -50,6 +51,8 @@
D1107C072110259000073188 /* RCTVideo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RCTVideo.h; path = Video/RCTVideo.h; sourceTree = "<group>"; };
D1107C082110259000073188 /* RCTVideoPlayerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RCTVideoPlayerViewController.m; path = Video/RCTVideoPlayerViewController.m; sourceTree = "<group>"; };
D1107C092110259000073188 /* RCTVideoManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RCTVideoManager.h; path = Video/RCTVideoManager.h; sourceTree = "<group>"; };
FA5A7A592270E5870086953B /* AVPlayerViewController+Fullscreen.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "AVPlayerViewController+Fullscreen.h"; path = "Video/AVPlayerViewController+Fullscreen.h"; sourceTree = "<group>"; };
FA5A7A5A2270E5870086953B /* AVPlayerViewController+Fullscreen.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "AVPlayerViewController+Fullscreen.m"; path = "Video/AVPlayerViewController+Fullscreen.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -88,6 +91,8 @@
58B511D21A9E6C8500147676 = {
isa = PBXGroup;
children = (
FA5A7A592270E5870086953B /* AVPlayerViewController+Fullscreen.h */,
FA5A7A5A2270E5870086953B /* AVPlayerViewController+Fullscreen.m */,
D1107C072110259000073188 /* RCTVideo.h */,
D1107C052110259000073188 /* RCTVideo.m */,
D1107C092110259000073188 /* RCTVideoManager.h */,
Expand Down Expand Up @@ -163,6 +168,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = 58B511D21A9E6C8500147676;
Expand All @@ -184,6 +190,7 @@
D1107C0A2110259000073188 /* UIView+FindUIViewController.m in Sources */,
D1107C102110259000073188 /* RCTVideoPlayerViewController.m in Sources */,
D1107C0E2110259000073188 /* RCTVideoManager.m in Sources */,
FA5A7A5B2270E5870086953B /* AVPlayerViewController+Fullscreen.m in Sources */,
D1107C0C2110259000073188 /* RCTVideo.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
20 changes: 20 additions & 0 deletions ios/Video/AVPlayerViewController+Fullscreen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// NSObject+AVPlayerViewController_Fullscreen.h
// RCTVideo
//
// Created by Ash on 2019-04-24.
// Copyright © 2019 Facebook. All rights reserved.
//

#import <AVKit/AVKit.h>
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface AVPlayerViewController (Fullscreen)

-(void)goFullscreenWithCompletionHandler:(void (^)(void)) completionBlock;

@end

NS_ASSUME_NONNULL_END
42 changes: 42 additions & 0 deletions ios/Video/AVPlayerViewController+Fullscreen.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// NSObject+AVPlayerViewController_Fullscreen.m
// RCTVideo
//
// Created by Ash on 2019-04-24.
// Copyright © 2019 Facebook. All rights reserved.
//

#import "AVPlayerViewController+Fullscreen.h"

@implementation AVPlayerViewController (Fullscreen)

-(void)goFullscreenWithCompletionHandler:(void (^)(void)) completionBlock {
NSString *selectorForFullscreen = @"transitionToFullScreenViewControllerAnimated:completionHandler:";
if (@available(iOS 11.3, *)) {
selectorForFullscreen = @"transitionToFullScreenAnimated:interactive:completionHandler:";
} else if (@available(iOS 11.0, *)) {
selectorForFullscreen = @"transitionToFullScreenAnimated:completionHandler:";
}
SEL fsSelector = NSSelectorFromString([@"_" stringByAppendingString:selectorForFullscreen]);
if ([self respondsToSelector:fsSelector]) {
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:fsSelector]];
[inv setSelector:fsSelector];
[inv setTarget:self];

NSInteger index = 2; //arguments 0 and 1 are self and _cmd respectively, automatically set
BOOL animated = YES;
[inv setArgument:&(animated) atIndex:index];
index++;

if (@available(iOS 11.3, *)) {
BOOL interactive = YES;
[inv setArgument:&(interactive) atIndex:index]; //arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation
index++;
}

[inv setArgument:&(completionBlock) atIndex:index];
[inv invoke];
}
}

@end
28 changes: 19 additions & 9 deletions ios/Video/RCTVideo.m
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,6 @@ - (void)dvAssetLoaderDelegate:(DVAssetLoaderDelegate *)loaderDelegate

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{

if([keyPath isEqualToString:readyForDisplayKeyPath] && [change objectForKey:NSKeyValueChangeNewKey] && self.onReadyForDisplay) {
self.onReadyForDisplay(@{@"target": self.reactTag});
return;
Expand Down Expand Up @@ -1264,14 +1263,25 @@ - (void)setFullscreen:(BOOL) fullscreen {
if(self.onVideoFullscreenPlayerWillPresent) {
self.onVideoFullscreenPlayerWillPresent(@{@"target": self.reactTag});
}
[viewController presentViewController:_playerViewController animated:true completion:^{
_playerViewController.showsPlaybackControls = YES;
_fullscreenPlayerPresented = fullscreen;
_playerViewController.autorotate = _fullscreenAutorotate;
if(self.onVideoFullscreenPlayerDidPresent) {
self.onVideoFullscreenPlayerDidPresent(@{@"target": self.reactTag});
}
}];

if (_controls) {

[_playerViewController removeFromParentViewController];
[_playerViewController goFullscreenWithCompletionHandler:^{

_playerViewController.showsPlaybackControls = YES;
_playerViewController.autorotate = _fullscreenAutorotate;
}];
} else {
[viewController presentViewController:_playerViewController animated:true completion:^{
_playerViewController.showsPlaybackControls = YES;
_fullscreenPlayerPresented = fullscreen;
_playerViewController.autorotate = _fullscreenAutorotate;
if(self.onVideoFullscreenPlayerDidPresent) {
self.onVideoFullscreenPlayerDidPresent(@{@"target": self.reactTag});
}
}];
}
}
}
else if ( !fullscreen && _fullscreenPlayerPresented )
Expand Down
1 change: 1 addition & 0 deletions ios/Video/RCTVideoPlayerViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import <AVKit/AVKit.h>
#import "RCTVideo.h"
#import "RCTVideoPlayerViewControllerDelegate.h"
#import "AVPlayerViewController+Fullscreen.h"

@interface RCTVideoPlayerViewController : AVPlayerViewController
@property (nonatomic, weak) id<RCTVideoPlayerViewControllerDelegate> rctDelegate;
Expand Down