0
votes

I have problems embedding Youtube videos in a iOS6 app.

The problem is that whenever I create a html element that uses the old / or new embed code, it opens Safari and shows the video

I use the Youtube API to get videos, and use PhoneGap

Update The solution is to set OpenAllWhitelistURLsInWebView to YES in Phonegap settings

2
It is fixed now, we had to set OpenAllWhitelistURLsInWebView to YES in Phonegap settingsbartburkhardt

2 Answers

0
votes

You can use UIWebview to load videos instead of Safari.

Here is a sample code

CGRect rect = [[UIScreen mainScreen] bounds];
CGSize screenSize = rect.size;

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,screenSize.width,screenSize.height)];
webView.autoresizesSubviews = YES;
webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);

NSString *videoUrl = @"http://www.youtube.com/v/oHg5SJYRHA0";
NSString *htmlString = [NSString stringWithFormat:@"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"320\" height=\"480\"><param name=\"movie\" value=\"%@\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"320\" height=\"480\"></embed></object></div></body></html>",videoUrl,videoUrl]    ;


[webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.youtube.com"]];

[window addSubview:webView];
[webView release]; 
0
votes

Not shure if you are talking a real APP (dont know anything about that)
but if its a WEBAPP (a normal webpage that tries to look as a real APP),
Then the only way i found to prevent youtube-videos from opening in Safari/Qt-player
is to embed it using "Fancybox" (maybe other boxes also).
that will keep it on the page in Youtube´s own player.

You can even have a original playlistplayer.
I stopped trying to embed youtube videos on iPhone-pages (to small)

I tried to include a link to a jSfiddle-example but this forum wont accept it it forces me to write the whole example here...which i´m not going to do because that is to much work for me right now.
(dont know how others are allowed to link to jSfiddle)
This forum is way to dictative to my taste.
Anyway you should be able to (incase of a webapp) find info at Fancybox´s website.