为什么这个嵌入式iframe视频没有播放?

时间:2015-08-14 06:17:37

标签: javascript html iframe video youtube

我想在我的网站上添加此视频。我添加了这段代码,但它没有用。请帮帮我。

<div id="container">
  <iframe id="vid" width="560" height="315" src="https://www.youtube.com/watch?v=NhxVR2Szu3k&noredirect=1" frameborder="0" allowfullscreen></iframe>
</div>
<style>
#container {
    border: 1px solid red;
    width: 560px;
    text-align: center;
}
#vid {
    margin-bottom: 25px;   
}
</style>

2 个答案:

答案 0 :(得分:2)

<强>已更新 请将其替换为您的代码

<div id="container">
  <iframe width="560" height="315" src="https://www.youtube.com/embed/NhxVR2Szu3k" frameborder="0" allowfullscreen></iframe>
</div>

和css

#container {
    border: 1px solid red;
    text-align:center;
    width: 80%;
    margin-left:auto;
    margin-right:auto;
}

因为你没有在视频链接中使用正确的视频代码..然后分享然后嵌入代码并获取代码并且它将起作用..希望这个帮助。

更新:现在您的视频已响应。根据您的需要更改宽度。

答案 1 :(得分:0)

我没有清楚地了解你想要实现的目标,但尝试这个例子:

&#13;
&#13;
<html>
<head> </head>
<body>  
            <div style="text-align:center"> 
              <button onclick="playPause()">Play/Pause </button> 
              <br> 
              <video id="video" width="420">
                <source src="video.mp4" type="video/mp4">
                Your browser does not support HTML5 video.
              </video>
            </div> 
            
            <script> 
            var myVideo = document.getElementById("video "); 
            
            function playPause() { 
                if (myVideo.paused) 
                    myVideo.play(); 
                else 
                    myVideo.pause(); 
            } 
            </script>               
</body>
</html>
&#13;
&#13;
&#13;