开发者

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';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜