我想在我的应用程序中播放YouTube视频。我写了下面的代码,但视频无法播放,请告诉我如何播放视频,在此先感谢
NSURL *url =[NSUrl UrlWithString: @"http://www.youtube.com/watch?v=2MSMJgpmVM8&feature=grec_index"];;
NSString *embedHTML = @"<html><head>\
<body style=\"margin: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];
答案 0 :(得分:0)
答案 1 :(得分:0)
答案 2 :(得分:0)
我使用以下函数将HTML放在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];
}
答案 3 :(得分:0)
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
答案 4 :(得分:0)
以下代码应该有效 -
但请注意,youtube仅适用于设备,您是否在设备上进行了检查。
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];