【问题标题】:How to stop programmatically a Youtube video embedded inside UIWebView xcode如何以编程方式停止嵌入在 UIWebView xcode 中的 Youtube 视频
【发布时间】:2014-11-14 23:27:10
【问题描述】:

我有一个用 XCode6.1 为 iPad 开发的应用程序

我有一个带有嵌入视频的 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,播放器仍然在播放视频,我希望它停止,该怎么做???

【问题讨论】:

    标签: xcode webview


    【解决方案1】:

    来自 Google 开发网站的 iOS Helper Library 帮助了我很多。 非常简单!

    https://developers.google.com/youtube/v3/guides/ios_youtube_helper

        - (IBAction)playVideo:(id)sender {
          [self.playerView playVideo];
        }
    
        - (IBAction)stopVideo:(id)sender {
          [self.playerView stopVideo];
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-03
      • 2011-09-11
      • 1970-01-01
      相关资源
      最近更新 更多