2012-09-14 145 views
12

你好我有webviews的應用程序,我嵌入了youtube視頻。 現在我安裝了iOS6,但他們不再工作。iOS 6嵌入youtube

有人已經找到解決方案嗎?

mycode的:

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

閱讀發行說明的iOS 6中有一份說明這一點。 –

+1

蘋果刪除了原生的Youtube應用,這實際上是在以前的iOS中播放Youtube視頻的原因。我試圖找到替代品,但沒有運氣。 –

+0

你整理過了嗎? – Daniel

回答

11

偉大的問題和一個問題,我只是注意到,出去找到解決方案。

我做下Safari的/ WebKit的部分了iOS 6發行說明中找到這句話:

隨着iOS 6後,在 http://www.youtube.com/watch?v=oHg5SJYRHA0將不再起作用的形式嵌入YouTube網址。這些 網址用於查看YouTube網站上的視頻,而不是用於在網頁中嵌入 。相反,應使用的格式在此處描述爲 :https://developers.google.com/youtube/player_parameters

返回谷歌開發者網站,它似乎應該通過使用iframe嵌入視頻播放器,不應該是太多的工作。

希望有所幫助。

3

如果您不需要straigh進自動播放,那麼你也許可以用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> 
+0

你是什麼意思5.1(5.0)開發工具包? –

+3

舊版基礎SDK,我已經編輯過,以消除混淆。 – PetrV

+0

非常感謝,我使用5.0作爲基礎sdk構建它,它工作了 –

5

//從淇淇的幫助,我已經在iOS6的發揮YouTube視頻如下,它是爲我工作

//這是我的YouTube的URL: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];