简体   繁体   English

Safari iOS 15 视频问题

[英]Safari iOS 15 video issue

Since I downloaded iOS 15, the video on my page no longer works (in Safari).自从我下载了 iOS 15,我页面上的视频不再有效(在 Safari 中)。 I used the following code to embed the video.我使用以下代码嵌入视频。

<video id="video" autoplay="true" loop="true" muted="true" playsinline="true">
    <source src="media/video.mp4" type="video/mp4">
</video>

If I deactivate "GPU Process: Media" in the Safari settings, everything works again as before.如果我在 Safari 设置中停用“GPU Process: Media”,一切都会像以前一样工作。

Do I have to embed the video differently?我必须以不同方式嵌入视频吗?

I was doing some experiments on this and found that the video will start working when we do pause and play.我对此做了一些实验,发现当我们暂停和播放时,视频会开始工作。

   const rVideo = document.getElementById("videoElement");
    if (rVideo) {
      rVideo.pause();
      rVideo
        .play()
        .then((res) => {
          console.log("playing start", res);
        })
        .catch((err) => {
          console.log("error playing", err);
        });
    }

It's not a perfect solution but a workaround to make it work.这不是一个完美的解决方案,而是使其工作的解决方法。

You can fix the black screen by using setTimeout as follows:您可以使用setTimeout修复黑屏,如下所示:

this.video.pause();
setTimeout(() => {
    this.video.play().then((res) => {
        console.log("playing start", res);
    })
    .catch((err) => {
        console.log("error playing", err);
    });
}, 0);

Just wrap the video tag in div.只需将视频标签包装在 div 中。 i'm guessing that you positioned your video tag absolute or fixed.我猜您将视频标签定位为绝对或固定。 There seems to be a bug with that.似乎有一个错误。 Positioning the wrapper div fixed/absolute instead of the video element seems to help.将包装器 div 定位为固定/绝对而不是视频元素似乎有帮助。 ( it might also help to give the video element a background color ) (它也可能有助于为视频元素提供背景颜色)

To be correctly served on IOS devices, the videos must be able to be requested even partially as specified by Apple.为了在 IOS 设备上正确播放,视频必须能够按照 Apple 的规定进行部分请求。 Therefore the 'byte-range support' must be enabled on the server on which they are hosted: https://discussions.apple.com/thread/4119538?page=2因此,必须在托管它们的服务器上启用“字节范围支持”: https : //discussions.apple.com/thread/4119538?page=2

Because of the number of complaints there have been of iPhones not being able to play some podcasts, Apple now require the server you host your media files on to have 'byte-range support' enabled - basically this means coping with requests for only part of a file at a time, which is required for the iPhone.由于 iPhone 无法播放某些播客的投诉数量众多,Apple 现在要求您托管媒体文件的服务器启用“字节范围支持”——基本上这意味着只处理部分请求一次一个文件,这是 iPhone 所必需的。 You should confirm with your hosting service that they support this: if they don't (or don't know what it is) you should find another hosting service.您应该与您的托管服务商确认他们是否支持这一点:如果他们不支持(或不知道它是什么),您应该找到其他托管服务。

Also if you are using Cloudflare as a CDN service, and gzip compression is enabled on the server the 'Accept-Ranges' header is not forwarded by Cloudflare and the videos are not properly served: https://community.cloudflare.com/t/accept-ranges-and-content-length-headers-not-forwarded-by-cloudflare/41445/4此外,如果您使用 Cloudflare 作为 CDN 服务,并且在服务器上启用了 gzip 压缩,则 Cloudflare 不会转发“Accept-Ranges”标头,并且视频无法正确提供: https : //community.cloudflare.com/t /accept-ranges-and-content-length-headers-not-forwarded-by-cloudflare/41445/4

Therefore there are two solutions:因此有两种解决方案:

  1. Completely disable gzip compression on the server.在服务器上完全禁用 gzip 压缩。
  2. Enable gzip compression on the server and add SetEnvIfNoCase Request_URI \\.mp4$ no-gzip dont-vary## Heading ## to the .htaccess file so as not to compress .mp4 files.在服务器上启用 gzip 压缩并将SetEnvIfNoCase Request_URI \\.mp4$ no-gzip dont-vary## Heading ##到 .htaccess 文件中,以免压缩 .mp4 文件。 The solution is applicable for any video format.该解决方案适用于任何视频格式。

I am using HTML Canvas element as the video source to publish the video.我使用 HTML Canvas 元素作为视频源来发布视频。 All I have been getting is a black screen and sometimes the first frame loads but ends up with a black screen.我得到的只是一个黑屏,有时第一帧加载但以黑屏结束。

The only two attributes i have been setting explicitly are playsinline and muted , here is a snippet for the same:我明确设置的唯一两个属性是playsinlinemuted ,这是相同的片段:

var videoEl = document.createElement('video');
videoEl.srcObject = mediaStream;
videoEl.setAttribute('playsinline', '');
videoEl.muted = true;

and after the render I end up with the below:在渲染之后我得到以下结果:

<video autoplay muted playsinline src="..."></video>

But since the latest OS update, the issue seems to be fixed.但自从最新的操作系统更新后,这个问题似乎得到了解决。 I tested my video call application in the below scenarios: Chrome → Chrome → Working as expected.我在以下场景中测试了我的视频通话应用程序:Chrome → Chrome → 按预期工作。 Chrome → Safari→ Working as expected. Chrome → Safari→ 按预期工作。 Safari → Safari → Working as expected. Safari → Safari → 按预期工作。

Version details: Chrome - 100.0.4896.75 Safari - 15.4 Mac OS - 12.3.1版本详细信息: Chrome - 100.0.4896.75 Safari - 15.4 Mac OS - 12.3.1

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

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