How to solve the problem of playback delay of audio tags on mobile iOS

1. How to solve the problem of playback delay of audio tags on mobile iOS?
2, and why the canplay event is not triggered under the mobile iOS, but can be triggered if the load () method of HTMLMediaElement is called first?

let audioDom = document.createElement("audio");
let sourceDom = document.createElement("source");
sourceDom.type = "audio/mpeg";
sourceDom.src = src;
audioDom.preload = "auto";
audioDom.appendChild(sourceDom);
audioContainer.appendChild(audioDom);
audioDom.load();

// 
audioDom.oncanplay = (e) => {
    let _audioDom = e.target;
    // this.totalTime = _audioDom.duration;
    _audioDom.play();
}
audioDom.onplay = (e) => {
    console.log("onplay")
}
Nov.26,2021

for this audio element of createElement, there is no way to solve the delay problem. You can use other methods, such as defining the audio tag in advance to specify the resource path with src.

Menu