From 52fbb46cc9ec88fc3b0187f17a2be359251ca082 Mon Sep 17 00:00:00 2001 From: Ian Hirschfeld Date: Wed, 16 Nov 2016 10:23:04 -0800 Subject: [PATCH 1/4] Adds ability to pass in UIWebView options. --- Classes/YTPlayerView.h | 2 ++ Classes/YTPlayerView.m | 26 ++++++++++++++++++++++++-- youtube-ios-player-helper.podspec | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Classes/YTPlayerView.h b/Classes/YTPlayerView.h index 7923c15..eec1fe2 100644 --- a/Classes/YTPlayerView.h +++ b/Classes/YTPlayerView.h @@ -197,6 +197,8 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { */ - (BOOL)loadWithVideoId:(nonnull NSString *)videoId playerVars:(nullable NSDictionary *)playerVars; +- (BOOL)loadWithVideoId:(nonnull NSString *)videoId playerVars:(nullable NSDictionary *)playerVars webViewVars:(nullable NSDictionary *)webviewVars; + /** * This method loads the player with the given playlist ID and player variables. Player variables * specify optional parameters for video playback. For instance, to play a YouTube diff --git a/Classes/YTPlayerView.m b/Classes/YTPlayerView.m index b2e2df4..783e47d 100644 --- a/Classes/YTPlayerView.m +++ b/Classes/YTPlayerView.m @@ -87,6 +87,17 @@ - (BOOL)loadWithVideoId:(NSString *)videoId playerVars:(NSDictionary *)playerVar return [self loadWithPlayerParams:playerParams]; } +- (BOOL)loadWithVideoId:(NSString *)videoId playerVars:(NSDictionary *)playerVars webViewVars:(NSDictionary *)webViewVars { + if (!playerVars) { + playerVars = @{}; + } + if (!webViewVars) { + webViewVars = @{}; + } + NSDictionary *playerParams = @{ @"videoId" : videoId, @"playerVars" : playerVars, @"webViewVars": webViewVars }; + return [self loadWithPlayerParams:playerParams]; +} + - (BOOL)loadWithPlaylistId:(NSString *)playlistId playerVars:(NSDictionary *)playerVars { // Mutable copy because we may have been passed an immutable config dictionary. @@ -746,9 +757,20 @@ - (BOOL)loadWithPlayerParams:(NSDictionary *)additionalPlayerParams { NSString *embedHTML = [NSString stringWithFormat:embedHTMLTemplate, playerVarsJsonString]; [self.webView loadHTMLString:embedHTML baseURL: self.originURL]; [self.webView setDelegate:self]; - self.webView.allowsInlineMediaPlayback = YES; self.webView.mediaPlaybackRequiresUserAction = NO; - + + if ([playerParams objectForKey:@"webViewVars"]) { + NSMutableDictionary *webViewVars = [[NSMutableDictionary alloc] init]; + [webViewVars addEntriesFromDictionary:[playerParams objectForKey:@"webViewVars"]]; + BOOL allowsInlineMediaPlayback = [webViewVars objectForKey:@"allowsInlineMediaPlayback"] || YES; + BOOL allowsPictureInPictureMediaPlayback = [webViewVars objectForKey:@"allowsPictureInPictureMediaPlayback"] || YES; + self.webView.allowsInlineMediaPlayback = allowsInlineMediaPlayback; + self.webView.allowsPictureInPictureMediaPlayback = allowsPictureInPictureMediaPlayback; + } else { + self.webView.allowsInlineMediaPlayback = YES; + self.webView.allowsPictureInPictureMediaPlayback = YES; + } + if ([self.delegate respondsToSelector:@selector(playerViewPreferredInitialLoadingView:)]) { UIView *initialLoadingView = [self.delegate playerViewPreferredInitialLoadingView:self]; if (initialLoadingView) { diff --git a/youtube-ios-player-helper.podspec b/youtube-ios-player-helper.podspec index 8eee90f..670e12b 100644 --- a/youtube-ios-player-helper.podspec +++ b/youtube-ios-player-helper.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "youtube-ios-player-helper" - s.version = "0.1.6" + s.version = "0.1.7" s.summary = "Helper library for iOS developers that want to embed YouTube videos in their iOS apps with the iframe player API." From bb52dc4cbbf426c2d96be7f3ab41a1fb1f9740ef Mon Sep 17 00:00:00 2001 From: Ian Hirschfeld Date: Wed, 16 Nov 2016 11:04:07 -0800 Subject: [PATCH 2/4] Fixes boolean check from NSDictionary for webViewVars. --- Classes/YTPlayerView.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/YTPlayerView.m b/Classes/YTPlayerView.m index 783e47d..328f857 100644 --- a/Classes/YTPlayerView.m +++ b/Classes/YTPlayerView.m @@ -762,8 +762,8 @@ - (BOOL)loadWithPlayerParams:(NSDictionary *)additionalPlayerParams { if ([playerParams objectForKey:@"webViewVars"]) { NSMutableDictionary *webViewVars = [[NSMutableDictionary alloc] init]; [webViewVars addEntriesFromDictionary:[playerParams objectForKey:@"webViewVars"]]; - BOOL allowsInlineMediaPlayback = [webViewVars objectForKey:@"allowsInlineMediaPlayback"] || YES; - BOOL allowsPictureInPictureMediaPlayback = [webViewVars objectForKey:@"allowsPictureInPictureMediaPlayback"] || YES; + BOOL allowsInlineMediaPlayback = [webViewVars objectForKey:@"allowsInlineMediaPlayback"] ? [[webViewVars objectForKey:@"allowsInlineMediaPlayback"] boolValue] : YES; + BOOL allowsPictureInPictureMediaPlayback = [webViewVars objectForKey:@"allowsPictureInPictureMediaPlayback"] ? [[webViewVars objectForKey:@"allowsPictureInPictureMediaPlayback"] boolValue] : YES; self.webView.allowsInlineMediaPlayback = allowsInlineMediaPlayback; self.webView.allowsPictureInPictureMediaPlayback = allowsPictureInPictureMediaPlayback; } else { From 4c856a5003d21908de31b6640e37b718d5fff424 Mon Sep 17 00:00:00 2001 From: Ian Hirschfeld Date: Wed, 16 Nov 2016 11:05:48 -0800 Subject: [PATCH 3/4] Removes modifying version number. --- youtube-ios-player-helper.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube-ios-player-helper.podspec b/youtube-ios-player-helper.podspec index 670e12b..8eee90f 100644 --- a/youtube-ios-player-helper.podspec +++ b/youtube-ios-player-helper.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "youtube-ios-player-helper" - s.version = "0.1.7" + s.version = "0.1.6" s.summary = "Helper library for iOS developers that want to embed YouTube videos in their iOS apps with the iframe player API." From d9dfac3566dc98844d31d6edb86d40931156acfa Mon Sep 17 00:00:00 2001 From: Ian Hirschfeld Date: Wed, 16 Nov 2016 11:56:52 -0800 Subject: [PATCH 4/4] Fixes typo. --- Classes/YTPlayerView.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/YTPlayerView.h b/Classes/YTPlayerView.h index eec1fe2..e478d4c 100644 --- a/Classes/YTPlayerView.h +++ b/Classes/YTPlayerView.h @@ -197,7 +197,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { */ - (BOOL)loadWithVideoId:(nonnull NSString *)videoId playerVars:(nullable NSDictionary *)playerVars; -- (BOOL)loadWithVideoId:(nonnull NSString *)videoId playerVars:(nullable NSDictionary *)playerVars webViewVars:(nullable NSDictionary *)webviewVars; +- (BOOL)loadWithVideoId:(nonnull NSString *)videoId playerVars:(nullable NSDictionary *)playerVars webViewVars:(nullable NSDictionary *)webViewVars; /** * This method loads the player with the given playlist ID and player variables. Player variables