I am trying to watch videos in my iphone app using the following code:
-(void) viewDidLoad{
[super viewDidLoad];
UIWebView *webView = [[UIWebView alloc]initWithFrame:self.view.frame];
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>";
// Populate HTML with the URL and requested frame size
NSString *html = [NSString stringWithFormat:youTubeVideoHTML,@"http://www.youtube.com/watch?v=ZiIcqZoQQwg" , 100, 100];
// Load the html into the webview
[webView loadHTMLString:html baseURL:nil];
[self.view addSubview:webView];
}
Can anyone tell me what I am doing wrong? I've seen this in a couple examples but still I can't work it out!
It looks like your HTML string isn't properly formed.
Try this:
It's worth noting that this code will only work on a device, it won't work in the simulator.
UPDATE...
Due to changes made by YouTube, the method above is now incorrect. Use the method below instead.
I have the same problem. I solved this by following method.
Replace the youtube Use http://www.youtube.com/v/XXXXXXX
instead of http://www.youtube.com/watch?v=XXXXXXX
try this simple one :