2013-07-02 41 views
9

如何在全屏幕上訪問移動(iPhone)safari(webkit)功能上的webkitExitFullScreeniOS上的YouTube IFrame API和webkitExitFullScreen [重溫]

在使用IFrame API的iPhone上,視頻始終播放全屏,但後來不能通過JS訪問不同的功能,如webkitExitFullScreen

我看到了這個已經被提交到論壇和球隊在YouTube API Forum在這裏:

https://groups.google.com/d/msg/youtube-api-gdata/fygn23jMbdE/pNE57RDl1gEJ

https://groups.google.com/forum/#!msg/youtube-api-gdata/7ioV74oFX84/U8zQ7-Yl9w4J

我想問問和跟進在他們的問題上,特別是上一次,因爲它已經是一年前了。但這些團體現在已經關閉,並表示我應該在這裏提交。有沒有人有任何想法,如果這已經在the API某處已經實施,我可能會錯過它?或者,也許如何聯繫團隊並直接詢問他們的進展情況?

+0

贊明智的,我想知道這裏是否有更新? @index你有沒有得到任何地方? – addedlovely

+0

@addedlovely不,還沒有。這實際上對我們來說現在成了一個限制。 :(任何東西在你身邊? – index

+0

@addedlovely我已經在google的youtube API這裏提交了這個https://code.google.com/p/gdata-issues/issues/detail?id=5710#makechanges,他們提到這個是不是在他們的計劃很快: – index

回答

1

寫這在您的viewDidLoad

webView112 = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
webView112.backgroundColor = [UIColor redColor]; 
webView112.allowsInlineMediaPlayback = YES; 
webView112.mediaPlaybackRequiresUserAction = NO; 
webView112.delegate = self; 
[self.view addSubview:webView112]; 

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"youtube" ofType:@"html"]; 
NSString *html = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; 

[webView112 loadHTMLString:html baseURL:[NSURL URLWithString:@"any static url"]]; 

和下面的方法將您的視頻

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ 
if ([[[request URL] scheme] isEqualToString:@"callback"]) 
{ 

    NSLog(@"get callback"); 
    [webView112 removeFromSuperview]; 

    return NO; 
} 

return YES;} 

完成後,消防和創建HTML文件並粘貼此代碼在.html文件

<html> 
<head> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> 

    <script> 
     var elapsed = -1; 
     var isPlayerLoaded = false; 
     var tag = document.createElement('script'); 
     tag.src = "http://www.youtube.com/player_api"; 
     var firstScriptTag = document.getElementsByTagName('script')[0]; 
     firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 

     // 4. The API will call this function when the video player is ready. 
     function onPlayerReady(event) { 
      player.playVideo(); 
     } 

     //   function onPlayerError(event) { 
     //   } 
     // 
     function onPlayerStateChange(event) { 
      var state = ''; 
      switch(event.data) { 
       case YT.PlayerState.ENDED: 
        window.location = "callback:anything"; 
        break; 
       case YT.PlayerState.PLAYING: 
        state = 'playing'; 
        break; 
       case YT.PlayerState.PAUSED: 
        state = 'paused'; 
        break; 
       case YT.PlayerState.BUFFERING: 
        state = 'buffering'; 
        break; 
       case YT.PlayerState.CUED: 
        state = 'cued'; 
        break; 
       default: 
        state = 'unstarted'; 
        break; 
      } 
      jQuery('#log').append(state + "<br/>"); 
     } 

     // 3. This function creates an <iframe> (and YouTube player) 
     // after the API code downloads. 
     var player; 
     function onYouTubePlayerAPIReady() { 
      player = new YT.Player('player', { 
            height: '400', 
            width: '320', 
            videoId: 'y84oAUjA8ms', 
            playerVars: { 'autoplay': 0, 'modestbranding': 1, 'rel': 0, 'showinfo': 0, 'iv_load_policy': 3, 'controls': 1, 'playsinline':1 }, 
            events: { 
            'onReady': onPlayerReady, 
            'onStateChange': onPlayerStateChange 
            //          'onError': onPlayerError 
            } 
            }); 
     } 

     </script> 
</head> 
<body style="padding:0;margin:0;background-color:#000000;"> 
    <div id="log" style="background:#fff;height:0px;width:0%;margin-top:0px;"></div> 
    <div id="player" frameborder="0"></div> 
</body>