2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

iOSでもバックグラウンドでWeb Audio APIの音が鳴るようにする

Last updated at Posted at 2024-06-07

問題提起

iPhone、iPadなどに搭載されているmobile safariの仕様により、WebAudioAPI経由で出した音はホーム画面に戻った際に中断されます。
もう一度safariを開いた際に音は中断したところから再開されますが、以下のコードを記述すればバックグラウンドでも音が再生され続けます。

解決策

解決策.js
/* let audioContext; */

window.addEventListener("visibilitychange", () => {
    if (document.visibilityState !== "hidden") {
        return;
    }
    audioContext.resume();
});

もっといい方法があれば教えてください🙇‍♂️

参考文献

(最終閲覧日はいずれも2024/06/08)

2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?