LoginSignup
1

More than 3 years have passed since last update.

iOSのJavaScriptでサウンド(WebAudio)の再生開始が遅い

Last updated at Posted at 2019-09-17

(Androidでは試してませんが、)iOSでAudio再生すると再生開始までタイムラグがあるようです。

測定してみました。

ソースコード

Vue.jsで作ったのでこんな感じです。

測定は読み込みではなくてあくまで.play()部分です。

<template>
  <div>
    <button @click="beep">Beep</button>
  </div>
</template>

<script>
〜〜
methods: {
    beep: function() {
      const beep = new Audio('/sounds/Ping.wav');
      beep.addEventListener('play', (s) => {
        const tm = new Date();
        console.log(s.type, tm - start);
      });
      beep.addEventListener('ended', (s) => {
        const tm = new Date();
        console.log(s.type, tm - start);
      });
      const start = new Date();
      beep.play();
    }
〜〜
<script>

測定結果

Macでは再生開始までは0 msecや1 msecでほぼタイムラグがありませんが、iPhone8だと18〜20msecほどになりました。

なんとかならないものか...

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
1