The video displays on the iPad. You can tap to bring up the controls. The fullscreen button is shown in the lower right, but tapping on it does nothing. It should send the player into fullscreen mode. Is there anything I can add to this code to make it work?
NSString *htmlStr = [NSString stringWithFormat:#"<body style=\"margin:0;padding:0;\" ><iframe class=\"youtube-player\" type=\"text/html\" width=\"420\" height=\"226\" src=\"http://www.youtube.com/embed/%#\" frameborder=\"0\" allowfullscreen></iframe>",video_ID];
UIWebView *videoView = [[UIWebView alloc] initWithFrame:thumb.frame];
videoView.backgroundColor = [UIColor darkGrayColor];
videoView.scrollView.scrollEnabled = NO;
[videoView loadHTMLString:htmlStr baseURL:nil];
[videoCcontainer addSubview:videoView];
Try using embed, and not an iframe: http://mobiledevelopertips.com/video/display-youtube-videos-without-exiting-your-application.html
NSString *youTubeVideoHTML = #"<html><head>\
<body style=\"margin:0\">\
<embed id=\"yt\" src=\"%#\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
Related
I am trying to add UIWebView in my UIViewController like this.
NSString *youTubeVideoHTML = #"<html><head><style>body{margin:0px 0px 0px 0px;}</style></head> <body> <div id=\"player\"></div> <script> var tag = document.createElement('script'); tag.src = 'http://www.youtube.com/player_api'; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function onYouTubePlayerAPIReady() { player = new YT.Player('player', { width:'320', height:'568', videoId:'%#', events: { 'onLoad': onPlayerReady } }); } function onPlayerReady(event) { event.target.playVideo(); } </script> </body> </html>";
NSString *strYoutubeId = [arrSearchAssignmentList[indexPath.row][#"id"][#"$t"] stringByReplacingOccurrencesOfString:#"http://gdata.youtube.com/feeds/api/videos/" withString:#""];
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, strYoutubeId];
videoView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
videoView.backgroundColor = [UIColor clearColor];
videoView.opaque = NO;
[self.view addSubview:videoView];
videoView.mediaPlaybackRequiresUserAction = NO;
[videoView loadHTMLString:html baseURL:[[NSBundle mainBundle] resourceURL]];
Here I want to hide UIWebView when done button clicked.
So is there anyway to hide the UIWebView when the done button is clicked or how can I handle the done button in the `UIWebView when it plays a video in full screen?
When you click DONE button it will stop playing video.If you are working on NAtive app then there will be only one Webview.
Or if you are working on Hybrid app. Then there will be two Webviews. One on which you run your app and one on which you can play video.
Outside Webview show Close button on click of which you can hide the Webview.
I use UIWebView to load a html page which contains only one SVG image file with below code:
self.webView = [UIWebView new];
self.webView.opaque = YES;
self.webView.frame = self.view.frame;
[_webView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)];
self.webView.dataDetectorTypes = UIDataDetectorTypeAll;
self.webView.userInteractionEnabled = YES;
_webView.scalesPageToFit = YES;
self.webView.delegate=self;
[self.view addSubview:self.webView];
and I take the a screen capture as below, I want to make the image file can be auto zoom in to fit the whole window when View is shown, currently I had to double tab the image to make it happen.
and belwo is what I expected:
Found the answer
NSString *jsCommand = [NSString stringWithFormat:#"document.body.style.zoom = 1.5;"];
[_webview stringByEvaluatingJavaScriptFromString:jsCommand];
I'm trying to implement an Adobe Edge animation inside a UIWebView in my IOS7 app. But all I get is a white screen. The same white screen shows up on my iPhone's Safari. The animation runs fine on my laptop's browsers, both Safari and Chrome.
I'm thinking this is an Adobe Edge problem, but here's my IOS code anyway:
NSString *filePathString = [[NSBundle mainBundle] pathForResource:#"YallaBye_Button2" ofType:#"html"];
NSMutableString *html = [[NSMutableString alloc] initWithContentsOfFile:filePathString encoding:NSUTF8StringEncoding error:nil];
NSURL *aURL = [NSURL fileURLWithPath:filePathString];
UIWebView *view = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
view.delegate = self;
[view stringByEvaluatingJavaScriptFromString:#"window.requestAnimationFrame = window.setTimeout;"];
[view loadHTMLString:html baseURL:aURL];
[self.indicatorForPlans addSubview:view];
The indicator works fine without the Adobe Edge html.
I also tried running the [view stringByEvaluatingJavaScriptFromString:#"window.requestAnimationFrame = window.setTimeout;"]; call inside the UIWebViewDelegate method - (void)webViewDidFinishLoad:(UIWebView *)webView but no luck.
Also, researching the forums, I tried changing my transform:translateX(0px); to -webkit-perspective: 1000; -webkit-backface-visibility: hidden; but still just a white screen.
What am I missing?
I have a simple ViewController to load FB comments plugins inside a UIWebView
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320.0f, 1505.0f)];
NSString * html = #"\
<!DOCTYPE html>\
<html xmlns:fb='http://ogp.me/ns/fb#'>\
<head>\
<meta name='viewport' content='width=device-width, initial-scale=1.0'>\
</head>\
<body style='background-color:red;'>\
\
<div id='fb-root'></div>\
<script>(function(d, s, id) {\
var js, fjs = d.getElementsByTagName(s)[0];\
if (d.getElementById(id)) return;\
js = d.createElement(s); js.id = id;\
js.src = 'http://connect.facebook.net/en_US/all.js#xfbml=1&appId=xxx';\
fjs.parentNode.insertBefore(js, fjs);\
}(document, 'script', 'facebook-jssdk'));</script>\
\
<fb:comments href='http://example.com' num_posts='10'></fb:comments>\
\
</body>\
</html>\
";
[webView loadHTMLString:html baseURL:nil];
[self.view addSubview:webView];
I can see the comments being loaded, but just the height is strange, seems auto resize failed? I can view the whole comments if I am using mobile safari.
you can use this code for displaying the fb comment in iOS UIWebview
UIWebView *fbWebview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 1505)];
[fbWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"https://www.facebook.com/Levis"]]];
CGRect scrollViewFrame = CGRectMake(0, 0, 320, 1024);
UIScrollView *scrollViewMain = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
CGSize scrollViewContentSize = CGSizeMake(320, 1505);
[scrollViewMain setContentSize:scrollViewContentSize];
[scrollViewMain setBounces:NO];
[scrollViewMain setScrollEnabled:YES];
[scrollViewMain setShowsVerticalScrollIndicator:YES];
[scrollViewMain setBackgroundColor:[UIColor redColor]];
[scrollViewMain addSubview:fbWebview];
[self.view addSubview:scrollViewMain];
instead of "https://www.facebook.com/Levis" use your FB URL
this may help you
You need to specify a baseURL
[webView loadHTMLString:html baseURL:[NSURL URLWithString:#"http://www.example.com"]];
#Howard you can use http://www.facebook.com/plugins/comments.php?href=http://www.google.com' scrolling='yes' profile='yes' frameborder='0' style='border:none; overflow:hidden; width:300px; height:30px;' data-href='http://www.google.com' allowTransparency='true'>"
Same problem here. The solution was not to use a local HTML file (or HTML string). Upload the HTML file to an server and use:
NSURL *url = [NSURL URLWithString:#"http://www.blablblab.com/yourfile.html"];
[self.webview loadRequest:[NSURLRequest requestWithURL:url]];
instead of:
[self.webview loadHTMLString:localString baseURL:nil];
I didn't discovered yet why there is a difference in the layout when the file is on a server, but when it is a local file, the height of my Facebook Comments View was always reduced to "height:160". Apparently it's because of the "all.js" facebook script (accordingly to this question).
I've come across a rather strange problem. What I'm trying to do right now is only obtain the audio of a YouTube video for a given link. I've tried a couple of things but it either didn't work or wasn't efficient.
Thus I've decided to ask more experienced iOS developers in here. Thanks in advance.
#implementation ViewController
#synthesize web;
- (void)embedYouTube:(NSString*)url frame:(CGRect)frame{
NSString* embedHTML = #"<html><head> <style type=\"text/css\">body {background-color: transparent;color: white;}</style></head><body style=\"margin:0\"><embed id=\"yt\" src=\"%#\" type=\"application/x-shockwave-flash\" width=\"%0.0f\" height=\"%0.0f\"></embed></body></html>";
NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height];
UIWebView *webView =[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[webView loadHTMLString:html baseURL:nil];
[self.view addSubview:webView];
}
-(IBAction)play{
[self embedYouTube:#"http://www.youtube.com/watch?v=iw1aT5c1Lus" frame:CGRectMake(0, 0, 320, 480)];
}
just play the video with your media player, but dont give it a frame, this will play the audio, but not load the image