【问题标题】:How to play video in Html如何在 Html 中播放视频
【发布时间】:2015-01-28 10:04:30
【问题描述】:

我在网站上播放视频时遇到问题。首先,我在本地使用了下面的代码,这些代码可以工作。但是,当我公开此页面时,视频无法播放并给出“没有支持格式或 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> 

【问题讨论】:

  • 您使用的是什么浏览器?我假设您在这两种情况下都使用相同的浏览器?
  • 这将帮助您了解浏览器中的视频htmlgoodies.com/html5/client/…
  • 我使用的是 firefox,但 Internet Explorer 和 google chrome 给了我同样的错误
  • 阅读caniuse.com/#feat=video及其子功能。
  • 你需要什么IE条件标签(gt IE 6)?

标签: javascript html video


【解决方案1】:

您没有 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>

【讨论】:

  • video id="video1" width="640" height="360" controls="controls">
  • 是真的。如何在这个页面播放mp4视频文件。 .ogg 视频可用,但 .mp4 文件不可用
  • @mehmet 所有 mozilla 文档都将 ogg 列为首选视频类型,但要与跨浏览器兼容,您应该真正提供 .ogg、.webm 和 .mp4,您可以在 video-convert-online.com 进行转换
【解决方案2】:

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

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

Here你可以阅读更多相关信息

【讨论】:

  • 我使用 IIS 服务器。我检查了你的链接,但页面是关于 apache 服务器的。你知道任何其他解决方案吗?
猜你喜欢
  • 1970-01-01
  • 2013-08-27
  • 1970-01-01
  • 2013-06-02
  • 2019-10-12
  • 1970-01-01
  • 1970-01-01
  • 2014-06-13
  • 1970-01-01
相关资源
最近更新 更多