admin管理员组

文章数量:1191171

Here's the description:

On iOS (iPhone or iPad) the following behaviour happens:

  • when both an HTML video element and an HTML audio element are playing on a web page,
  • and the video source ends,
  • and the video source is programmatically forced to play again

then the system will automatically pause the audio.

See following stackblitz project for a sample:

.md

Its code is not really that much: most buttons work on both audio and video elements at once. When either audio or video notifies its end through an event, it is then programmatically rewound.

Steps to reproduce

Feel free to try with both another audio and video source, here limited by the available space in Stackblitz plan.

On an iPhone/iPad device or simulator, in Safari:

  1. browse to index.html
  2. when on iPhone, press iPhone Load to force preloading video. Not needed on iPad
  3. press Play to start playing both audio and video
  4. wait until clip ends and then restarts from 0:00

Expected

Audio should keep on playing and eventually loop.

Actual

When clip restarts from 0, audio is put to pause by the system.

Further details

This does not happen e.g. on Mac Safari nor on another device/browser. It also seems not strictly related to O.S. version: it happens both with iPadOS 17.x and iOS 18.x.
Also, some alternative scenarios:

  • on HTML video end, if only play is invoked without resetting current time, the issue is still present
  • on HTML video end, if only current time is reset without start playing it again, the issue disappears
  • when HTML video element has the muted attribute, the issue disappears and audio is not paused
  • when HTML audio element is replaced with Web Audio API, the issue disappears and audio is not paused

I posted this question on Apple Developer forums, but I'm not really sure it'll receive a lot of feedback from there, being the topic not related to native apps.

This automatic behaviour comes kind of unexpected: it does not happen e.g. on MacOS, nor Android, now Windows. But maybe I am wrong: is this expected? And is there a way to avoid it?

本文标签: audioHTMLAudioElement on iOS is paused when video plays againStack Overflow