iOS 6 嵌入 youtube

标签 ios youtube ios6

你好,我有一个带有 WebView 的应用程序,我嵌入了 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];
}

最佳答案

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

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

As of iOS 6, embedded YouTube URLs in the form of http://www.youtube.com/watch?v=oHg5SJYRHA0 will no longer work. These URLs are for viewing the video on the YouTube site, not for embedding in web pages. Instead, the format that should be used is described here: https://developers.google.com/youtube/player_parameters.

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

希望对您有所帮助。

关于iOS 6 嵌入 youtube,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12429969/

相关文章:

javascript - 使Vimeo或youtube在模式打开时播放,并在模式关闭时停止视频播放

javascript - "Unsafe JavaScript attempt to access frame with URL"错误导致 JavaScript 翻转失败

xcode - iOS 6 : present a modal view controller

iphone - iOS 6 map View 中缩放级别的无关行为

ios - 使用 StoreKit 检测应用安装

ios - Swift:UILabel 如何显示所有文本

objective-c - 即使使用默认 568h@2x 图像,iOS 应用程序也不会使用 4 英寸尺寸

android - ScrollView Android中的YouTube播放器

ios - dateFromComponents 给出了错误的日期

ios - 评估 NSString 大小以填充 UITextView