【问题标题】:iOS 6 embed youtubeiOS 6 嵌入 youtube
【发布时间】:2012-09-07 22:34:10
【问题描述】:

您好,我有带有 webviews 的应用程序,并且我嵌入了 youtube 视频。 现在我安装了 iOS6,但它们不再工作了。

有人已经找到解决方案了吗?

我的代码:

- (void)viewDidLoad
{
    [scrollvideoView setScrollEnabled:YES];
    [scrollvideoView setContentSize:CGSizeMake(320,2300)];
    [scrollvideoView setPagingEnabled:NO];

    [super viewDidLoad];
    // Do any additional setup after loading the view.

    //Variabelen
    NSInteger x1 = 25;
    NSInteger x2 = 123;
    NSInteger x3 = 220;
    NSInteger sz = 75;

    //Label height rij1
    NSInteger yt1 = 45;

    /* de Videos */
    //Eerste rij
    NSInteger y1 = 0;
    [self embedYouTube:@"http://www.youtube.com/watch?v=MFARZYEGqK8" frame:CGRectMake(x1, y1, sz, sz)];
    [self embedYouTube:@"http://www.youtube.com/watch?v=cD7WHGvXqEA" frame:CGRectMake(x2, y1, sz, sz)];
    [self embedYouTube:@"http://www.youtube.com/watch?v=8onqmHPBJOo" frame:CGRectMake(x3, y1, sz, sz)];

    //Setting de labels
    UILabel *videoLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(x1, yt1, sz, sz)];
    videoLabel1.text = @"Videoclip daor heb ik schijt an";
    [self.scrollvideoView addSubview:videoLabel1];
    videoLabel1.backgroundColor = [UIColor clearColor];
    videoLabel1.font = [UIFont fontWithName:@"Arial" size: 9.0];
    videoLabel1.textColor = [UIColor whiteColor];

    UILabel *videoLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(x2, yt1, sz, sz)];
    videoLabel2.text = @"Videoclip goeie been verkeerde bed";
    [self.scrollvideoView addSubview:videoLabel2];
    videoLabel2.backgroundColor = [UIColor clearColor];
    videoLabel2.font = [UIFont fontWithName:@"Arial" size: 9.0];
    videoLabel2.textColor = [UIColor whiteColor];

    UILabel *videoLabel3 = [[UILabel alloc] initWithFrame:CGRectMake(x3, yt1, sz, sz)];
    videoLabel3.text = @"Wavin flag (giel beelen)";
    [self.scrollvideoView addSubview:videoLabel3];
    videoLabel3.backgroundColor = [UIColor clearColor];
    videoLabel3.font = [UIFont fontWithName:@"Arial" size: 9.0];
    videoLabel3.textColor = [UIColor whiteColor];

    //Tweede rij
    NSInteger y2 = 100;
    [self embedYouTube:@"http://www.youtube.com/watch?v=-cJz3YGRlMI" frame:CGRectMake(x1, y2, sz, sz)];
    [self embedYouTube:@"http://www.youtube.com/watch?v=ZdQRcAnPCvk" frame:CGRectMake(x2, y2, sz, sz)];
    [self embedYouTube:@"http://www.youtube.com/watch?v=KNcT5O1qk40" frame:CGRectMake(x3, y2, sz, sz)];

}

- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame {`
    /*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, urlString, frame.size.width,`frame.size.height];
    UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
    [videoView loadHTMLString:html baseURL:nil];
    [self.scrollvideoView addSubview:videoView];
    //[videoView release];
}

【问题讨论】:

  • 阅读 iOS 6 的发行说明。里面有关于这个的说明。
  • Apple 移除了原生 Youtube 应用程序,这确实是在以前的 iOS 中播放 Youtube 视频所涉及的内容。我正在寻找替代品,但还没有运气。

标签: ios youtube ios6


【解决方案1】:

如果您不需要直接自动播放,那么您也许可以使用 iframe 和播放按钮

      <iframe height="90" width="75" src="http://www.youtube.com/embed/VIDEOID"></iframe>  

,当您按下播放按钮时,全屏播放器会接管(至少对于我在 iOS 6 中的应用)

如果您使用较旧的 Base SDK 5.1 (5.0) 编译应用,即使在 iOS 6 中,任何类型的旧 YouTube 嵌入都应该仍然有效。例如:

 <embed src="http://www.youtube.com/watch?v=VIDEOID" type="application/x-shockwave-flash"     widht="64" height="64"></embed>

【讨论】:

  • 5.1 (5.0) 开发套件是什么意思?
【解决方案2】:

很好的问题和一个我刚刚注意到并正在寻找解决方案的问题。

我确实在 Safari/WebKit 部分下的 iOS 6 发行说明中找到了这句话:

从 iOS 6 开始,嵌入的 YouTube URL 格式为 http://www.youtube.com/watch?v=oHg5SJYRHA0 将不再起作用。这些 URL 用于在 YouTube 网站上观看视频,而不是用于嵌入 在网页中。而是描述了应该使用的格式 这里:https://developers.google.com/youtube/player_parameters

回到谷歌开发者网站,似乎视频播放器应该使用 iframe 嵌入,不应该做太多的工作。

希望对您有所帮助。

【讨论】:

    【解决方案3】:

    //来自 Qiqi 帮助我在 ios6 中播放了 youtube 视频,如下所示,它对我有用

    //这是我的 youtube 网址:http://www.youtube.com/watch?v=s9KU-oOa6pA

    //VIDEOID:s9KU-oOa6pA

         CGRect frame = CGRectMake(5,55, 310,200);
         NSString *embedHTML =[NSString stringWithFormat:@"\
                              <html><head>\
                              <style type=\"text/css\">\
                              body {\
                              background-color: transparent;\
                              color: blue;\
                              }\
                              </style>\
                              </head><body style=\"margin:0\">\
                              <iframe height=\"200\" width=\"310\"      src=\"http://www.youtube.com/embed/s9KU-oOa6pA\"></iframe>\
                              </body></html>"];
        UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
    
       videoView.backgroundColor = [UIColor clearColor];
       [videoView loadHTMLString:embedHTML baseURL:nil];
        [self.view addSubview:videoView];
    

    【讨论】:

      猜你喜欢
      • 2012-12-02
      • 2014-11-10
      • 2015-10-29
      • 1970-01-01
      • 2014-04-16
      • 2020-06-14
      • 2014-04-01
      • 2016-11-26
      • 2011-08-20
      相关资源
      最近更新 更多