未播放嵌入的youtube视频



我有一个YouTube视频,上个月运行良好,但现在无法在iOS 6中播放。

这是我尝试过的代码。它正确地从YouTube播放视频,但当我点击播放按钮时,它不会播放视频,并显示错误消息:

此视频当前不可用

但这段视频可以在YouTube上看到,播放效果很好。苹果有什么更新吗?

- (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];
}

我使用了这个吊舱:

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];

享受吧。

使用以下代码对我来说很好。

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];

相关内容

  • 没有找到相关文章