找到你要的答案

Q:Why is this embedded iframe video not playing?

Q:为什么这是嵌入的iframe视频不玩吗?

I want to add this video on my website. I added this code but it’s not working. Please help me.

<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 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>
answer1: 回答1:

UPDATED Please replace this with your code

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

and css

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

as you are not using correct code for video..go in video link..then share and then embed code and take that code and it will work..hope this help.

Updated : now your video is responsive..change width according to your need.

UPDATED Please replace this with your code

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

由于您没有使用正确的视频代码..去视频链接..然后分享,然后嵌入代码,并采取该代码,它将工作..希望这方面的帮助。

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

answer2: 回答2:

I didn't clearly understand what you're trying to achieve but try this example:

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

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

<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>
javascript  html  iframe  video  youtube