如何在 Html 中播放视频

How to play video in Html

我在网站上播放视频时遇到问题。首先,我在本地使用了以下代码,这些代码有效。但是当我 public 此页面视频无法播放并出现 "no video with supported format or mime type " 这个错误时。我在 Windows 中使用 IIS 服务器。此页面在 ASP.NET 网站下运行。 这是 html 代码:

<div style="text-align:center"> 
  <button onclick="playPause()">Play/Pause</button> 
  <button onclick="makeBig()">Big</button>
  <button onclick="makeSmall()">Small</button>
  <button onclick="makeNormal()">Normal</button>
  <br> 
<video width="640" height="360"   controls="controls">
    <source src="files/Just.mp4" type="video/mp4" />

    <object width="640" height="375" type="video/quicktime" data="files/Just.mp4"><!--<![endif]-->
    <param name="src" value="files/Just.mp4" />
    
    <param name="autoplay" value="true" />
    <param name="showlogo" value="false" />
    <!--[if gt IE 6]><!-->
    </object><!--<![endif]-->
</video>
</div> 

<script>
    var myVideo = document.getElementById("video1");

    function playPause() {
        if (myVideo.paused)
            myVideo.play();
        else
            myVideo.pause();
    }

    function makeBig() {
        myVideo.width = 560;
    }

    function makeSmall() {
        myVideo.width = 320;
    }

    function makeNormal() {
        myVideo.width = 420;
    }
</script> 

尝试将此添加到您的 .htaccess 文件之上:

AddType video/mp4 mp4 m4v
AddType audio/mp4 m4a
AddType video/ogg ogv
AddType audio/ogg ogg oga
AddType video/webm webm

Here 你可以阅读更多相关内容

您没有video1的id。把它放在视频标签之后,然后它应该可以工作

<!DOCTYPE html>
<html>

<body>

  <div style="text-align:center">
    <button onclick="playPause()">Play/Pause</button>
    <button onclick="makeBig()">Big</button>
    <button onclick="makeSmall()">Small</button>
    <button onclick="makeNormal()">Normal</button>
    <br>
    <video id="video1" width="420">
      <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
        <source src="http://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg">
          <param name="autoplay" value="true" />
          <param name="showlogo" value="false" / Your browser does not support HTML5 video. </video>
  </div>

  <script>
    var myVideo = document.getElementById("video1");

    function playPause() {
      if (myVideo.paused)
        myVideo.play();
      else
        myVideo.pause();
    }

    function makeBig() {
      myVideo.width = 560;
    }

    function makeSmall() {
      myVideo.width = 320;
    }

    function makeNormal() {
      myVideo.width = 420;
    }
  </script>

</body>

</html>