【问题标题】:Youtube embedded video: autoplay feature not working in iphoneYoutube 嵌入视频:自动播放功能在 iphone 中不起作用
【发布时间】:2011-12-29 19:27:13
【问题描述】:

我在 HTML5 页面中有一个嵌入 youtube 的视频链接,我想将其发送到 autoplay

以下代码适用于浏览器,但适用于 iphone;它不起作用,需要额外的点击。

<iframe type="text/html" width="125" height="100" src="http://www.youtube.com/embed/d_g0251EfB8?autoplay=1" frameborder="0"></iframe>

做什么

【问题讨论】:

    标签: html youtube autoplay


    【解决方案1】:

    更新:

    iOS 10+ 现在允许在 HTML5

    示例:

    <video autoplay muted>
      <source src="movie.mp4" type="video/mp4">
      Sadly, your browser does not support the video tag X_x 
    </video>
    

    信息来源: https://webkit.org/blog/6784/new-video-policies-for-ios/

    【讨论】:

      【解决方案2】:

      我尝试了以下操作,当网络视图完成加载时,Youtube 视频成功地全屏自动播放:

      [self.webView setAllowsInlineMediaPlayback:YES];
      [self.webView setMediaPlaybackRequiresUserAction:NO];
      
      [self.view addSubview:self.webView];
      
      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='100%%' height='%f' src='http://www.youtube.com/embed/%@?enablejsapi=1&rel=0&playsinline=0&autoplay=1' frameborder='0'allowfullscreen>\
                             </body>\
                             </html>",self.webView.frame.size.height,@"Dw9jFO_coww"];
      
      
      [self.webView bringSubviewToFront:self.btnBack];
      self.webView.backgroundColor = [UIColor clearColor];
      self.webView.opaque = NO;
      [self.webView loadHTMLString:embedHTML baseURL:[[NSBundle mainBundle] resourceURL]];
      

      【讨论】:

      • 代码中充满了拼写错误并且缺乏清晰性:(哦,这很糟糕。
      • OP 要求的是 HTLM5 而不是 ObjC,不是吗?
      【解决方案3】:

      这是不可能的。由于各种原因(包括但不限于数据使用),Apple 不允许自动播放视频。

      the accepted answer to this question

      【讨论】:

      • 感谢。让我删除我的问题
      • @AvisekChakraborty:请不要删除它。这仍然是有用的信息,即使答案不是您所希望的。
      • 那么为什么比 facebook 和 instagram 能做到呢?
      • 请注意 YouTube iFrame Player API playVideo() 函数在移动设备上不起作用,如果您认为这是一个解决方案:(
      • 这很糟糕,实际上。防止滥用自动播放不应关闭程序化 API 的所有其他(和更好的)可能性。 Sanity 将是用户选择加入,以允许在每页甚至每次访问的基础上进行程序控制,而不仅仅是严厉的“全部禁止”。
      猜你喜欢
      • 2015-03-18
      • 2021-09-11
      • 2017-11-03
      • 1970-01-01
      • 2018-12-16
      • 2018-05-25
      • 2021-05-01
      相关资源
      最近更新 更多