【问题标题】:object is not taking full width in iphone对象没有在 iphone 中占据全宽
【发布时间】:2015-11-26 16:16:54
【问题描述】:

我想在 iphone cordova 应用中显示 youtube 视频,

我尝试了iframe,但它有时不显示。

所以尝试对象标签

我的代码是

<div style="width: 100%; padding: 0" id="getWidth">

   <object width="100%" height="auto">
       <param name="movie" value="http://www.youtube.com/v/{{youtubeId}}">
           <embed src="http://www.youtube.com/v/{{youtubeId}}" type="application/x-shockwave-flash" width="100%;" height="auto">
    </object>
</div>

这里getWidth 正在全屏显示,但视频没有全宽显示,如下图所示

注意:左侧 Safari 检查器和右侧 iphone 模拟器

图像是在尝试动态设置宽度时拍摄的,但在两种情况下结果都相同

【问题讨论】:

    标签: html ios iphone cordova video


    【解决方案1】:

    请参阅Youtube Player API,了解如何将其嵌入到您的应用程序中。 iframe 是迄今为止最好的方法。

    这是来自 API 的示例 html

    <!DOCTYPE html>
    <html>
      <body>
        <!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
        <div id="player"></div>
    
        <script>
          // 2. This code loads the IFrame Player API code asynchronously.
          var tag = document.createElement('script');
    
          tag.src = "https://www.youtube.com/iframe_api";
          var firstScriptTag = document.getElementsByTagName('script')[0];
          firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
    
          // 3. This function creates an <iframe> (and YouTube player)
          //    after the API code downloads.
          var player;
          function onYouTubeIframeAPIReady() {
            player = new YT.Player('player', {
              height: '390',
              width: '640',
              videoId: 'M7lc1UVf-VE',
              events: {
                'onReady': onPlayerReady,
                'onStateChange': onPlayerStateChange
              }
            });
          }
    
          // 4. The API will call this function when the video player is ready.
          function onPlayerReady(event) {
            event.target.playVideo();
          }
    
          // 5. The API calls this function when the player's state changes.
          //    The function indicates that when playing a video (state=1),
          //    the player should play for six seconds and then stop.
          var done = false;
          function onPlayerStateChange(event) {
            if (event.data == YT.PlayerState.PLAYING && !done) {
              setTimeout(stopVideo, 6000);
              done = true;
            }
          }
          function stopVideo() {
            player.stopVideo();
          }
        </script>
      </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2016-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-15
      • 2022-01-25
      • 1970-01-01
      • 2022-07-11
      • 1970-01-01
      相关资源
      最近更新 更多