Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Allows setting UIWebView parameters during instantiation #237

Open
wants to merge 4 commits into
base: master
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
2 changes: 2 additions & 0 deletions Classes/YTPlayerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 24 additions & 2 deletions Classes/YTPlayerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"] ? [[webViewVars objectForKey:@"allowsInlineMediaPlayback"] boolValue] : YES;
BOOL allowsPictureInPictureMediaPlayback = [webViewVars objectForKey:@"allowsPictureInPictureMediaPlayback"] ? [[webViewVars objectForKey:@"allowsPictureInPictureMediaPlayback"] boolValue] : 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) {
Expand Down