IPad Safari <audio> not playing
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';
精彩评论