简体   繁体   English

Safari 不播放.mp4 视频

[英]Safari doesn't play .mp4 videos

This works fine on Chrome, but not on Safari.这在 Chrome 上工作正常,但在 Safari 上不行。

<video id="video" class="video" preload="metadata" autoplay="" loop="" muted="" >
   <source src="images/video.mp4" type="video/mp4">
</video>

The mp4 video's Codecs is H.264. mp4 视频的编解码器是 H.264。 To play this video, I had to convert this mp4 to HEVC.要播放此视频,我必须将此 mp4 转换为 HEVC。 Voila, this solved it!瞧,这解决了它!

<video id="video" class="video" preload="metadata" autoplay="" loop="" muted="" >
            <!-- for safari - HEVC -->
            <source src="images/video.mp4" type="video/mp4"> 
            <!-- for chrome - H264 -->
            <source src="images/video.mp4" type="video/mp4">
</video>

I added a couple of more lines of code because this background video wasn't playing on mobile(iphone chrome and safari)我添加了几行代码,因为这个背景视频没有在移动设备上播放(iphone chrome 和 safari)

<video id="video" class="video" preload="metadata" autoplay muted loop playsinline>
        <!-- below is for safari - HEVC format -->
        <source src="images/home-video.mp4" type="video/mp4">
        <!-- for google -  H264 format -->
        <source src="images/hero-video.mp4" type="video/mp4">
        <!-- for mobile -->
        <source src="images/hero-video.webm" type="video/webm">
        <source src="images/hero-video.ogg" type="video/ogg">
</video>

Now I'm having an issue with this video not playing on Android(Chrome).. smh现在我遇到了这个视频无法在 Android(Chrome) 上播放的问题.. smh

A nice and simple hack is to simply duplicate the file and make use of the .m4v extension at the end instead of .mp4 and use content type video/x-m4v instead of video/mp4 .一个不错且简单的 hack 是简单地复制文件并在末尾使用.m4v扩展名而不是.mp4并使用内容类型video/x-m4v而不是video/mp4

example:例子:

<video preload="metadata" autoplay="" loop="" muted="" >
  <!-- for safari or iOS or anything Apple -->
  <source src="images/video.m4v" type="video/x-m4v">
  <!-- for chrome, firefox, android and remainig friends -->
  <source src="images/video.mp4" type="video/mp4">
</video>

See: https://en.wikipedia.org/wiki/M4V参见: https://en.wikipedia.org/wiki/M4V

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM