cannot play iPad <audio> over https

2019-07-18 05:58发布

问题:

I am trying to play HTML5 on iPad Safari . Below is my code;

var audio = document.createElement('audio');
    audio.type = "audio/mpeg";
    audio.src = audioUrl;         
    x.appendChild(audio);
    audio.load();
    audio.play();

Now my audio files are called over https and for some reasons, it cannot play audio over https...I mean if I try manually playing mp3 files on http, it plays them fine..

How do I fix this issue?

回答1:

var audio = document.createElement('audio');
audio.type = "audio/mp3";
audio.src = audioUrl;         
x.appendChild(audio);
audio.load();
audio.play();

audio/mpeg may be the issue. Safari on iOS (including iPad) currently supports uncompressed WAV and AIF audio, MP3 audio, and AAC-LC or HE-AAC audio. HE-AAC is the preferred format.