嵌入到 HTML 中的视频无法播放

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23192565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:35:18  来源:igfitidea点击:

Video embedded into HTML doesn't play

htmlflashvideohtml5-video

提问by Frank G.

I am trying to accomplish a very simple task; at least I would think it should be but its not.

我正在尝试完成一项非常简单的任务;至少我认为它应该是但它不是。

I am trying to embed video into HTML and nothing I try seems to works. Here is the code I am using to do it:

我正在尝试将视频嵌入到 HTML 中,但我尝试的任何内容似乎都不起作用。这是我用来执行此操作的代码:

<video width="560" height="340" controls>
    <source src="video/30.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>  
    <source src="video/30.ogv" type='video/ogg; codecs="theora, vorbis"'>

    <object width="640" height="384" type="application/x-shockwave-flash"   data="video/player_flv_maxi.swf?image=placeholder.jpg&file=video/30.swf">
    <param name="movie" value="video/player_flv_maxi.swf?image=placeholder.jpg&file=video/30.swf" />
    </object>
</video>

I am using this resource to try and accomplish this: http://www.webmonkey.com/2010/05/embed-videos-in-your-web-pages-using-html5/

我正在使用此资源来尝试完成此操作:http: //www.webmonkey.com/2010/05/embed-videos-in-your-web-pages-using-html5/

I also have tried: http://www.w3schools.com/html/html5_video.asp

我也试过:http: //www.w3schools.com/html/html5_video.asp

And none of those seem to work. Can someone please tell me why none of the video formats I have listed above play in Google Chrome? Is there something wrong with the code?

这些似乎都不起作用。有人可以告诉我为什么上面列出的视频格式都不能在 Google Chrome 中播放吗?代码有问题吗?

采纳答案by Frank G.

I figured out what my problem was. It has to do with including the MIME Type to your IIS. I found this webpage that got me up and running in know time:

我想出了我的问题是什么。它与在 IIS 中包含 MIME 类型有关。我发现这个网页让我在知道的时间内启动并运行:

http://blog.arvixe.com/to-play-mp4-video-in-asp-net-you-may-need-to-add-a-mime-type/

http://blog.arvixe.com/to-play-mp4-video-in-asp-net-you-may-need-to-add-a-mime-type/

Make sure if you are running Mircosoft IIS that you have the MIME Type added to IIS so IIS knows what to do when someone tries to load a mp4 video type. Thanks all for the help!

确保您在运行 Mircosoft IIS 时将 MIME 类型添加到 IIS,以便 IIS 在有人尝试加载 mp4 视频类型时知道该怎么做。感谢大家的帮助!

回答by brianchirls

Your HTML is fine and is likely not the problem. I put together a test JS Bin and changed the video URLs (except for the Flash fallback), and it works just fine for me in Chrome and Firefox.

您的 HTML 很好,可能不是问题。我整理了一个测试 JS Bin 并更改了视频 URL(Flash 回退除外),它在 Chrome 和 Firefox 中对我来说很好用。

http://jsbin.com/musod/1/edit

http://jsbin.com/musod/1/edit

Without having your actual site to test, I can suggest a few possibilities:

无需您的实际站点进行测试,我可以提出几种可能性:

  1. The video files are not in the right place on the server, so you're getting 404 or 503 errors on them.

  2. The video files are not encoded correctly in a way the browser can play them. This may be the case if the wrong codec was used or if the bit rate is way too high (not super likely).

  3. The HTML got mangled somehow, like if you pasted into a hosting platform like wordpress or something that is expecting plain text with minimal formatting HTML.

  1. 视频文件不在服务器上的正确位置,因此您会收到 404 或 503 错误。

  2. 视频文件没有以浏览器可以播放的方式正确编码。如果使用了错误的编解码器或比特率太高(不太可能),可能会出现这种情况。

  3. HTML 以某种方式被破坏了,就像你粘贴到一个托管平台,比如 wordpress 或一些期望使用最小格式 HTML 的纯文本的东西。

Here are some steps you can take to diagnose the problem. Feel free to report the results in the comments here if you need further direction.

以下是您可以采取的一些步骤来诊断问题。如果您需要进一步的指导,请随时在此处的评论中报告结果。

  1. Check the browser consolefor error messages.

  2. Paste the full URL of the video file(s) right into the browser. This should show you if there's a 404, 503 or some other error that's causing the files not to load.

  3. Check the "Network" panel in developer tools to make sure you have the correct URL and see if it's loading the file.

  4. Drag the video file right into the browser and see if it plays. This will show you if there is a problem with the encoding. The browser shouldbe able to play the video on its own, without any extra HTML.

  5. View the HTML sourceof the webpage to confirm that the server is delivering the HTML just as you wrote it. For example, make sure it hasn't converted your "angle brackets" to html entitiesor changed the quotes to "smart quotes".

  1. 检查浏览器控制台是否有错误消息。

  2. 将视频文件的完整 URL 粘贴到浏览器中。这应该会告诉您是否存在 404、503 或其他导致文件无法加载的错误。

  3. 检查开发人员工具中的“网络”面板,确保您拥有正确的 URL,并查看它是否正在加载文件。

  4. 将视频文件直接拖到浏览器中,看看它是否可以播放。这将显示编码是否有问题。浏览器应该能够自己播放视频,不需要任何额外的 HTML。

  5. 查看网页的 HTML 源代码以确认服务器是否按照您编写的方式提供 HTML。例如,确保它没有将您的“尖括号”转换为 html 实体或将引号更改为“智能引号”。

回答by Palmer

HTML5 video still requires a lot of work, you should try using a player plugin, I've always used jPlayer. http://jplayer.org

HTML5 视频仍然需要大量工作,您应该尝试使用播放器插件,我一直使用 jPlayer。http://jplayer.org