LoginSignup
7
2

More than 5 years have passed since last update.

Safariでvideo.play()したときにAbortErrorと言われたときの対応

Last updated at Posted at 2019-04-22

※2019年4月22日現在の話です。videoの変更次第ではこの対応では不十分になるかもしれません。
※音声付きの動画を自動再生したいケースには非対応です。(できるかどうかも未検証です)

状況

iOS12 の Safari で、video.play() した際に、Unhandled Promise Rejection: AbortError: The operation was aborted.が発生する。
この際、動画が再生されることもあればされないこともある。(多分再生されないのが正しい動き)

対応

参考サイトにあるとおり、 video.muted = trueplaysinline を設定する。
また、 autoplay は使わないようにする。

修正前

const video = document.createElement("video");
video.autoplay = true;
video.srcObject = stream;
video.play();

修正後

const video = document.createElement("video");
video.muted = true;
video.playsinline = true;
video.srcObject = stream;
video.play();

参考

https://lealog.hateblo.jp/entry/2018/03/27/161141
https://github.com/bbc/VideoContext/issues/66

7
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
2