Ios Wechat version 6.7.1 will not trigger canplay? before playing after the audio is loaded.

Target: get the file length before the audio is played.
Terminal: ios Wechat version 6.7.1
phenomenon: the canplay event will only be triggered when the user manually clicks the play button.

related codes

  var audio = document.getElementById("audio");

  audio.addEventListener("canplay", function(e) {
     console.log(audio.duration);
  });
What is the reason for

? What are we going to do about it?

Jun.21,2021

canplay can only be triggered by clicking play on ios. If you want to obtain the duration, you can try the loadedmetadata event

.
audio.addEventListener('loadedmetadata', function (e) {
  console.log(this.duration)
})
Menu