I want to play an mp3 on iPad Safari.. Here is my code
var audio = document.createElement('audio');
audio.src = audioUrl;
x.appendChild(audio);
audio.play();
For some reasons, i get an error..movie cannot be played, even though it is mp3..
Though works fine on Windows Safari..
I have tried 2 things;
var audio = document.createElement('audio');
audio.type = "audio/mpeg";
audio.src = audioUrl;
x.appendChild(audio);
audio.play();
and
x.innerHTML = '<audio autoplay=autoplay><source src="'+audioUrl + '" type=audio/mpeg /></audio>';
Please help. Thank you.
You have to add:
audio.type='audio/mpeg';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.