为什么这个嵌入的 iframe 视频不播放?

Why is this embedded iframe video not playing?

我想在我的网站上添加这个视频。我添加了这段代码,但它不起作用。请帮助我。

<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>

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

<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;
}

因为您没有为视频使用正确的代码..进入视频 link..然后分享然后嵌入代码并获取该代码,它会起作用..希望有帮助。

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

我不太清楚你想要达到什么目的,但试试这个例子:

<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>