如何在Html中播放视频

时间:2015-01-28 10:04:30

标签: javascript html video

我有在网站上播放视频的问题。首先,我在localy使用下面的代码,这些代码工作。但是,当我公开此页面时,视频无法播放,并且没有支持格式或mime类型的视频"这个错误。我在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> 
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

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

&#13;
&#13;
<!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>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

尝试在 .htaccess 文件上添加此内容:

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

Here你可以阅读更多关于它的信息