Skip to content

Commit

Permalink
perfomed improvements to player
Browse files Browse the repository at this point in the history
  • Loading branch information
JV17 committed Jan 16, 2015
1 parent 4368d0d commit 63d32fb
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 65 deletions.
4 changes: 2 additions & 2 deletions YoutubeHelper/YTPlayerView-iframe-player.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
height: '720',
width: '1280',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
Expand Down
4 changes: 3 additions & 1 deletion YoutubeHelper/YTPlayerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ typedef enum {

@property BOOL theme; // default is dark, available dark and light (if YES == light)

@property(nonatomic, strong, readonly) UIWebView *webView;
@property BOOL hd;

@property(nonatomic, strong) UIWebView *webView;

/** A delegate to be notified on playback events. */
@property(nonatomic, weak) id<YTPlayerViewDelegate> delegate;
Expand Down
66 changes: 25 additions & 41 deletions YoutubeHelper/YTPlayerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ @implementation YTPlayerView
@synthesize showinfo = _showinfo;
@synthesize start = _start;
@synthesize theme = _theme;
@synthesize hd = _hd;

- (BOOL)loadWithVideoId:(NSString *)videoId
{
Expand Down Expand Up @@ -435,7 +436,7 @@ - (NSArray *)availableQualityLevels

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// NSLog(@"***** Checking ERROR -> %@", request.URL.absoluteString);
NSLog(@"***** Checking Loading -> %@", request.URL.absoluteString);

// if ([request.URL.absoluteString isEqualToString:@"ytplayer://onStateChange?data=2"])
// {
Expand All @@ -451,13 +452,11 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
if ([request.URL.absoluteString isEqualToString:@"ytplayer://onStateChange?data=3"])
{
[self playerStarted];

return NO;
}
if ([request.URL.absoluteString isEqualToString:@"ytplayer://onStateChange?data=2"])
else if ([request.URL.absoluteString isEqualToString:@"ytplayer://onStateChange?data=2"])
{
[self playerEnded];

return NO;
}
}
Expand Down Expand Up @@ -740,12 +739,12 @@ - (BOOL)handleHttpNavigationToUrl:(NSURL *) url
- (BOOL)loadWithPlayerParams:(NSDictionary *)additionalPlayerParams
{
// Remove the existing webView to reset any state
[self.webView removeFromSuperview];
if(_webView)
[_webView removeFromSuperview];

// creating webview for youtube player
static dispatch_once_t once;
dispatch_once(&once, ^{
_webView = [self createNewWebView];
[self addSubview:self.webView];
});

Expand Down Expand Up @@ -805,10 +804,7 @@ - (BOOL)loadWithPlayerParams:(NSDictionary *)additionalPlayerParams
NSLog(@"%@", embedHTML);

[self.webView loadHTMLString:embedHTML baseURL:[NSURL URLWithString:@"about:blank"]];
[self.webView setDelegate:self];
self.webView.allowsInlineMediaPlayback = YES;
self.webView.mediaPlaybackRequiresUserAction = NO;


return YES;
}

Expand Down Expand Up @@ -911,6 +907,8 @@ - (void)dealloc

- (void)webViewDidFinishLoad:(UIWebView*)webView
{
[self setPlaybackQuality:kYTPlaybackQualityHD720];

if(self.allowLandscapeMode)
{
// adding listener to webView
Expand Down Expand Up @@ -1016,34 +1014,30 @@ - (void)orientationChanged:(NSNotification*)notification


#pragma mark - Exposed for Testing
- (void)setWebView:(UIWebView *)webView
{
_webView = webView;
}

- (UIWebView *)createNewWebView
- (UIWebView *)webView
{
if(!_webView)
{
_webView = [[UIWebView alloc] initWithFrame:self.bounds];
_webView.delegate = self;
_webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
_webView.scrollView.scrollEnabled = NO;
_webView.scrollView.bounces = NO;
_webView.delegate = self;

return _webView;
_webView.allowsInlineMediaPlayback = YES;
_webView.mediaPlaybackRequiresUserAction = NO;
}

return _webView;
}

- (NSMutableDictionary*)setDicParameters
- (NSMutableDictionary*)dicParameters
{
if(!_dicParameters)
{
_dicParameters = [[NSMutableDictionary alloc] init];
return _dicParameters;
}

return _dicParameters;
}

Expand Down Expand Up @@ -1096,7 +1090,6 @@ -(BOOL)autohide {
-(void)setAutohide:(BOOL)autohide {

if(autohide == YES) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:@(1) forKey:@"autohide"];
}
_autohide = autohide;
Expand All @@ -1109,7 +1102,6 @@ -(BOOL)autoplay {
-(void)setAutoplay:(BOOL)autoplay {

if(autoplay == YES) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:@(1) forKey:@"autoplay"];
}
_autoplay = autoplay;
Expand All @@ -1122,7 +1114,6 @@ -(BOOL)cc_load_policy {
-(void)setCc_load_policy:(BOOL)cc_load_policy {

if(cc_load_policy == YES) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:@(1) forKey:@"cc_load_policy"];
}
_cc_load_policy = cc_load_policy;
Expand All @@ -1135,7 +1126,6 @@ -(BOOL)color {
-(void)setColor:(BOOL)color {

if(color == YES) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:@"white" forKey:@"color"];
}
_color = color;
Expand All @@ -1148,7 +1138,6 @@ -(BOOL)controls {
-(void)setControls:(BOOL)controls {

if(controls == YES) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:@(0) forKey:@"controls"];
}
_controls = controls;
Expand All @@ -1161,7 +1150,6 @@ -(BOOL)disablekb {
-(void)setDisablekb:(BOOL)disablekb {

if(disablekb == YES) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:@(1) forKey:@"disablekb"];
}
_disablekb = disablekb;
Expand All @@ -1174,7 +1162,6 @@ -(BOOL)enablejsapi {
-(void)setEnablejsapi:(BOOL)enablejsapi {

if(enablejsapi == YES) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:@(1) forKey:@"enablejsapi"];
}
_enablejsapi = enablejsapi;
Expand All @@ -1187,7 +1174,6 @@ -(int)end {
-(void)setEnd:(int)end {

if(end > 0) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:@(end) forKey:@"end"];
}
_end = end;
Expand All @@ -1200,7 +1186,6 @@ -(BOOL)fullscreen {
-(void)setFullscreen:(BOOL)fullscreen {

if(fullscreen == YES) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:@(0) forKey:@"fs"];
}
_fullscreen = fullscreen;
Expand All @@ -1213,7 +1198,6 @@ -(BOOL)iv_load_policy {
-(void)setIv_load_policy:(BOOL)iv_load_policy {

if(iv_load_policy == YES) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:@(3) forKey:@"iv_load_policy"];
}
_iv_load_policy = iv_load_policy;
Expand All @@ -1226,7 +1210,6 @@ -(NSString*)list {
-(void)setList:(NSString *)list {

if(list.length > 0) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:list forKey:@"list"];
}
_list = list;
Expand All @@ -1239,7 +1222,6 @@ -(NSString*)listType {
-(void)setListType:(NSString *)listType {

if(listType.length > 0) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:listType forKey:@"listType"];
}
_listType = listType;
Expand All @@ -1252,7 +1234,6 @@ -(BOOL)loops {
-(void)setLoops:(BOOL)loops {

if(loops == YES) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:@(1) forKey:@"loop"];
}
_loops = loops;
Expand All @@ -1265,7 +1246,6 @@ -(BOOL)modestbranding {
-(void)setModestbranding:(BOOL)modestbranding {

if(modestbranding == YES) {
_dicParameters = [self setDicParameters];
[_dicParameters setObject:[NSNumber numberWithInt:1] forKey:@"modestbranding"];
}
_modestbranding = modestbranding;
Expand All @@ -1278,7 +1258,6 @@ -(NSString*)playerapiid {
-(void)setPlayerapiid:(NSString *)playerapiid {

if(playerapiid.length > 0) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:playerapiid forKey:@"playerapiid"];
}
_playerapiid = playerapiid;
Expand All @@ -1291,7 +1270,6 @@ -(NSString*)playList {
-(void)setPlayList:(NSString*)playList {

if(playList.length > 0) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:playList forKey:@"playlist"];
}
_playList = playList;
Expand All @@ -1304,7 +1282,6 @@ -(BOOL)playsinline {
-(void)setPlaysinline:(BOOL)playsinline {

if(playsinline == YES) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:@(1) forKey:@"playsinline"];
}
_playsinline = playsinline;
Expand All @@ -1317,7 +1294,6 @@ -(BOOL)rel {
-(void)setRel:(BOOL)rel {

if(rel == YES) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:@(1) forKey:@"rel"];
}
_rel = rel;
Expand All @@ -1330,7 +1306,6 @@ -(BOOL)showinfo {
-(void)setShowinfo:(BOOL)showinfo {

if(showinfo == YES) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:@(0) forKey:@"showinfo"];
}
_showinfo = showinfo;
Expand All @@ -1343,7 +1318,6 @@ -(int)start {
-(void)setStart:(int)start {

if(start == YES) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:@(start) forKey:@"start"];
}
_start = start;
Expand All @@ -1356,10 +1330,20 @@ -(BOOL)theme {
-(void)setTheme:(BOOL)theme {

if(theme == YES) {
_dicParameters = [self setDicParameters];
[self.dicParameters setObject:@"light" forKey:@"theme"];
}
_theme = theme;
}

-(BOOL)hd {
return _hd;
}

-(void)setHd:(BOOL)hd {
if(hd == YES) {
[self.dicParameters setObject:@(1) forKey:@"hd"];
}
_hd = hd;
}

@end
Binary file not shown.
Loading

0 comments on commit 63d32fb

Please sign in to comment.