I want to play YouTube video in my Application. I written the code below but the video cant played please tell me how to play the video, Thanks in Advance
NSURL *url =[NSUrl UrlWithString: @"http://www.youtube.com/watch?v=2MSMJgpmVM8&feature=grec_index"];;
NSString *embedHTML = @"<html><head>\
<body style=\"mar开发者_如何学Gogin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
videoView = [[UIWebView alloc] initWithFrame:CGRectMake(100, 100, 320.0, 412.0)];
[videoView setOpaque:NO];
NSString *html = [NSString stringWithFormat:embedHTML,url, videoView.frame.size.width, videoView.frame.size.height];
[videoView loadHTMLString:html baseURL:nil];
[self.view addSubview:videoView];
hey i dont think you will need to embed anything.you can simply shoot the webView with the appropriate URL...i had done dis a week back...it played the videos in Youtube.. Cheerzz..!!
Please follow this Link1 and Link2
Just Pass your URL in fileURL
I use the following function to get the HTML to place in a UIWebView
- (NSString *)YouTubeHTMLForURL:(NSString *)URLString;
{
int w = streamWebView.frame.size.width;
int h = streamWebView.frame.size.height;
NSString *HTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
width:%dpx;\
height:%dpx;\
background-color:#252525;\
color:white;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%d\" height=\"%d\"></embed>\
</body></html>";
return [NSString stringWithFormat:HTML, w, h, URLString, w, h];
}
UIWebView *wbView = (UIWebView *)[self.view viewWithTag:1];
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, 64.0, 64.0];
[wbView loadHTMLString:html baseURL:nil];
"url" is your video url
@Mike video plays only on device not on simulator
This below code should work -
But Please note that youtube only works in device are you checking this on device.
UIWebView *wbView = (UIWebView *)[self.view viewWithTag:1];
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, 64.0, 64.0];
[wbView loadHTMLString:html baseURL:nil];
精彩评论