MM-20729 & MM-20731 Fix YouTube playback and rotation (#3624)

This commit is contained in:
Mattermost Build
2019-11-28 11:55:55 +01:00
committed by Elias Nahum
parent 5a16752275
commit ae6e3dfb6d
6 changed files with 89 additions and 47 deletions

View File

@@ -35,7 +35,7 @@ target 'Mattermost' do
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
pod 'XCDYouTubeKit', '~> 2.8'
pod 'XCDYouTubeKit', '2.8.2'
pod 'Swime', '3.0.6'
target 'MattermostTests' do

View File

@@ -40,7 +40,7 @@ PODS:
- Folly (= 2018.10.22.00)
- RCTRequired (= 0.61.2)
- React-Core (= 0.61.2)
- RCTYouTube (2.0.0-beta.3):
- RCTYouTube (2.0.0):
- React
- YoutubePlayer-in-WKWebView (~> 0.3.1)
- React (0.61.2):
@@ -297,7 +297,7 @@ PODS:
- Sentry/Core (= 4.4.0)
- Sentry/Core (4.4.0)
- Swime (3.0.6)
- XCDYouTubeKit (2.8.1)
- XCDYouTubeKit (2.8.2)
- Yoga (1.14.0)
- YoutubePlayer-in-WKWebView (0.3.3)
@@ -357,7 +357,7 @@ DEPENDENCIES:
- RNSVG (from `../node_modules/react-native-svg`)
- RNVectorIcons (from `../node_modules/react-native-vector-icons`)
- Swime (= 3.0.6)
- XCDYouTubeKit (~> 2.8)
- XCDYouTubeKit (= 2.8.2)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
SPEC REPOS:
@@ -490,7 +490,7 @@ SPEC CHECKSUMS:
libwebp: 057912d6d0abfb6357d8bb05c0ea470301f5d61e
RCTRequired: c639d59ed389cfb1f1203f65c2ea946d8ec586e2
RCTTypeSafety: dc23fb655d6c77667c78e327bf661bc11e3b8aec
RCTYouTube: a36b9960e040063877fb8dc61fff19d3bd1a97ff
RCTYouTube: 5e94bfa005371c41d307f3f93c51b3e8eabfb0c8
React: 7e586e5d7bec12b91c1a096826b0fc9ab1da7865
React-Core: 8ddb9770b4a30a6ab4a754e6ed5ec76454e3d699
React-CoreModules: b3d9eece8ad7df36c917a41f05c1168c52fe0b34
@@ -535,10 +535,10 @@ SPEC CHECKSUMS:
SDWebImageWebPCoder: 947093edd1349d820c40afbd9f42acb6cdecd987
Sentry: 26650184fe71eb7476dfd2737acb5ea6cc64b4b1
Swime: d7b2c277503b6cea317774aedc2dce05613f8b0b
XCDYouTubeKit: 4ca4e3322fa556ec1c32932d378365c15ce1386e
XCDYouTubeKit: 79baadb0560673a67c771eba45f83e353fd12c1f
Yoga: 14927e37bd25376d216b150ab2a561773d57911f
YoutubePlayer-in-WKWebView: 7694e858c5c3472ed067d6fe34eb9b944845e63c
PODFILE CHECKSUM: 807d95a6b7f45b6daddd86ab902e339f591ca8b0
PODFILE CHECKSUM: 5d115a6e48c4a1683c49388094e119a6e4679c8f
COCOAPODS: 1.7.5

8
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "mattermost-mobile",
"version": "1.25.0",
"version": "1.26.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -10962,9 +10962,9 @@
}
},
"react-native-youtube": {
"version": "2.0.0-beta.3",
"resolved": "https://registry.npmjs.org/react-native-youtube/-/react-native-youtube-2.0.0-beta.3.tgz",
"integrity": "sha512-43dSL8m1RJRD5Il4NytdBx/abwaLZcbBdZD6GFFZo0qppArspCAEsuiOLPL6nck2ydeDYFZ4LvoUm217IVUo8w==",
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/react-native-youtube/-/react-native-youtube-2.0.0.tgz",
"integrity": "sha512-i21jL4kyp2epgV0d2gPSNQ0JvuVSwUL1t6CUzcXZZY7ezTSA0FB4kR9/cWpu/Nd3kkrt6WnZtGYuWKIfzbVbUw==",
"requires": {
"prop-types": "^15.5.0"
}

View File

@@ -63,7 +63,7 @@
"react-native-vector-icons": "6.6.0",
"react-native-video": "5.0.2",
"react-native-webview": "github:mattermost/react-native-webview#b5e22940a613869d3999feac9451ee65352f4fbe",
"react-native-youtube": "2.0.0-beta.3",
"react-native-youtube": "2.0.0",
"react-navigation": "4.0.10",
"react-navigation-stack": "1.9.4",
"react-redux": "7.1.1",

View File

@@ -1,35 +0,0 @@
diff --git a/node_modules/react-native-youtube/RCTYouTubeStandalone.m b/node_modules/react-native-youtube/RCTYouTubeStandalone.m
index fabd291..9158a6a 100644
--- a/node_modules/react-native-youtube/RCTYouTubeStandalone.m
+++ b/node_modules/react-native-youtube/RCTYouTubeStandalone.m
@@ -14,6 +14,7 @@ @implementation RCTYouTubeStandalone {
RCT_REMAP_METHOD(playVideo,
playVideoWithResolver:(NSString*)videoId
+ startTime:(NSNumber* _Nonnull)startTime
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
@@ -38,10 +39,19 @@ @implementation RCTYouTubeStandalone {
streamURLs[@(XCDYouTubeVideoQualitySmall240)
];
- weakPlayerViewController.player = [AVPlayer playerWithURL:streamURL];
- [weakPlayerViewController.player play];
+ @try {
+ CMTime initialPlaybackTime = CMTimeMakeWithSeconds([startTime doubleValue], 1);
- resolve(@"YouTubeStandaloneIOS player launched successfully");
+ weakPlayerViewController.player = [AVPlayer playerWithURL:streamURL];
+ [weakPlayerViewController.player seekToTime:initialPlaybackTime completionHandler: ^(BOOL finished) {
+ [weakPlayerViewController.player play];
+ resolve(@"YouTubeStandaloneIOS player launched successfully");
+ }];
+ }
+ @catch (NSException *ex) {
+ reject(@"error", ex.reason, nil);
+ [root dismissViewControllerAnimated:YES completion:nil];
+ }
} else {
reject(@"error", error.localizedDescription, nil);
[root dismissViewControllerAnimated:YES completion:nil];

View File

@@ -0,0 +1,77 @@
diff --git a/node_modules/react-native-youtube/RCTYouTubeStandalone.m b/node_modules/react-native-youtube/RCTYouTubeStandalone.m
index fabd291..1e29586 100644
--- a/node_modules/react-native-youtube/RCTYouTubeStandalone.m
+++ b/node_modules/react-native-youtube/RCTYouTubeStandalone.m
@@ -5,6 +5,18 @@
#endif
@import AVKit;
+@interface AVPlayerViewControllerRotation : AVPlayerViewController
+
+@end
+
+@implementation AVPlayerViewControllerRotation
+
+- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
+ return UIInterfaceOrientationMaskAllButUpsideDown;
+}
+
+@end
+
@implementation RCTYouTubeStandalone {
RCTPromiseResolveBlock resolver;
RCTPromiseRejectBlock rejecter;
@@ -14,6 +26,7 @@ @implementation RCTYouTubeStandalone {
RCT_REMAP_METHOD(playVideo,
playVideoWithResolver:(NSString*)videoId
+ startTime:(NSNumber* _Nonnull)startTime
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
@@ -22,10 +35,10 @@ @implementation RCTYouTubeStandalone {
#else
dispatch_async(dispatch_get_main_queue(), ^{
UIViewController *root = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
- AVPlayerViewController *playerViewController = [AVPlayerViewController new];
+ AVPlayerViewControllerRotation *playerViewController = [AVPlayerViewControllerRotation new];
[root presentViewController:playerViewController animated:YES completion:nil];
- __weak AVPlayerViewController *weakPlayerViewController = playerViewController;
+ __weak AVPlayerViewControllerRotation *weakPlayerViewController = playerViewController;
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:videoId
completionHandler:^(XCDYouTubeVideo * _Nullable video, NSError * _Nullable error) {
@@ -38,10 +51,18 @@ @implementation RCTYouTubeStandalone {
streamURLs[@(XCDYouTubeVideoQualitySmall240)
];
- weakPlayerViewController.player = [AVPlayer playerWithURL:streamURL];
- [weakPlayerViewController.player play];
-
- resolve(@"YouTubeStandaloneIOS player launched successfully");
+ @try {
+ CMTime initialPlaybackTime = CMTimeMakeWithSeconds([startTime doubleValue], 1);
+ weakPlayerViewController.player = [AVPlayer playerWithURL:streamURL];
+ [weakPlayerViewController.player seekToTime:initialPlaybackTime completionHandler: ^(BOOL finished) {
+ [weakPlayerViewController.player play];
+ resolve(@"YouTubeStandaloneIOS player launched successfully");
+ }];
+ }
+ @catch (NSException *ex) {
+ reject(@"error", ex.reason, nil);
+ [root dismissViewControllerAnimated:YES completion:nil];
+ }
} else {
reject(@"error", error.localizedDescription, nil);
[root dismissViewControllerAnimated:YES completion:nil];
diff --git a/node_modules/react-native-youtube/YouTubeStandalone.ios.js b/node_modules/react-native-youtube/YouTubeStandalone.ios.js
index b5e1b3c..f7c9999 100644
--- a/node_modules/react-native-youtube/YouTubeStandalone.ios.js
+++ b/node_modules/react-native-youtube/YouTubeStandalone.ios.js
@@ -5,4 +5,4 @@ const { YouTubeStandalone } = NativeModules;
export const YouTubeStandaloneIOS = !YouTubeStandalone
? null
- : { playVideo: videoId => YouTubeStandalone.playVideo(videoId) };
+ : { playVideo: (videoId, startTime) => YouTubeStandalone.playVideo(videoId, startTime) };