2014-11-14 99 views
2

我在XCode6.1开发的iPad如何停止编程嵌入的UIWebView的Xcode内YouTube视频

有我有一个嵌入式的视频这一个UIWebView的应用程序的代码是:

[self.webView setAllowsInlineMediaPlayback:YES]; 
    [self.webView setMediaPlaybackRequiresUserAction:NO]; 

    NSString* embedHTML = [NSString stringWithFormat:@"\ 
          <html>\ 
          <body style='margin:0px;padding:0px;'>\ 
          <script type='text/javascript' src='http://www.youtube.com/iframe_api'></script>\ 
          <script type='text/javascript'>\ 
          function onYouTubeIframeAPIReady()\ 
          {\ 
          ytplayer=new YT.Player('playerId',{events:{onReady:onPlayerReady}})\ 
          }\ 
          function onPlayerReady(a)\ 
          { \ 
          a.target.playVideo(); \ 
          }\ 
          </script>\ 
          <iframe id='playerId' type='text/html' width='%f' height='%f' src='http://www.youtube.com/embed/%@?enablejsapi=1&rel=0&playsinline=1&autoplay=1' frameborder='0'>\ 
          </body>\ 
          </html>", self.webView.frame.size.width, self.webView.frame.size.height, @"JW5meKfy3fY"]; 
    [self.webView loadHTMLString:embedHTML baseURL:[[NSBundle mainBundle] resourceURL]]; 

但如果我切换到另一个ViewController,播放器仍然在播放视频,我希望它停止,该怎么做?

回答