我的YouTube视频在上个月运行良好,但现在无法在iOS 6中播放。
这是我试过的代码。它正确地从YouTube流式传输视频,但是当我点击播放按钮时,它不播放视频并显示错误消息:
此视频目前无法使用
但此视频可在YouTube上播放并播放效果良好。 Apple有任何更新吗?
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame = CGRectMake(100, 55, 500, 500);
NSString *strurl=@"http://www.youtube.com/embed/x1g53j4BY9Y?feature=player_embedded";
NSLog(@"stringwithurl===%@",strurl);
NSString *embedHTML =[NSString stringWithFormat:@"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: blue;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" height=\"500\" width=\"500\"src=\"%@\ type=\"application/x-shockwave-flash\"></embed>\
</body></html>",strurl];
UIWebView *webview=[[UIWebView alloc]initWithFrame:frame];
[self.view addSubview:webview];
[webview sizeToFit];
webview.scrollView.scrollEnabled = NO;
webview.scrollView.bounces = NO;
webview.backgroundColor = [UIColor clearColor];
[webview loadHTMLString:embedHTML baseURL:nil];
}
答案 0 :(得分:0)
我用过这个吊舱:
https://github.com/larcus94/LBYouTubeView
它很容易使用。
示例:
LBYouTubePlayerViewController* controller = [[LBYouTubePlayerViewController alloc] initWithYouTubeURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=1fTIhC1WSew&list=FLEYfH4kbq85W_CiOTuSjf8w&feature=mh_lolz"] quality:LBYouTubeVideoQualityLarge];
controller.delegate = self;
controller.view.frame = CGRectMake(0.0f, 0.0f, 200.0f, 200.0f);
controller.view.center = self.view.center;
[self.view addSubview:self.controller.view];
享受它。
答案 1 :(得分:0)
使用以下代码对我来说工作正常。
NSString *strurl=@"http://www.youtube.com/embed/x1g53j4BY9Y?feature=player_embedded";
NSString *htmlString = [NSString stringWithFormat:@"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = yes, width = 320\"/></head><body style=\"background:#00;margin-top:0px;margin-left:0px\"><div><object width=\"320\" height=\"180\"><param name=\"movie\" value=\"http://www.youtube.com/v/%@&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/v/%@&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"320\" height='%0.0f'></embed></object></div></body></html>", strurl, strurl,self.videoWebView.frame.size.height];
NSString *finalHtml = [NSString stringWithFormat:htmlString,self.videoWebView.frame.size.width,
self.videoWebView.frame.size.height,urlString];
[videoWebView loadHTMLString:finalHtml baseURL:nil];