I have an HTML5 audio player that should play when an element has been clicked. It works fine in all desktop browsers. It's just not working on the iPad.
I've read that ios doesn't support auto play and that a user must initiate the play...which as far as I'm aware is exactly what I'm doing by having my code within a click function?
var item = $('.type-aud'),
path = item.attr('file'),
html = '<audio controls><source src="'+path+'" type="audio/mpeg" class="audio"></audio><span class="play"></span>',
playerClass = item.find('.audio');
if (!playerClass.hasClass('audio')) {
item.append(html);
}
item.click(function() {
var player = item.find('audio');
if (!player.hasClass('playing')) {
$(player).addClass('playing').trigger("play").next().addClass('pause').removeClass('play');
} else {
$(player).removeClass('playing').trigger("pause").next().removeClass('pause').addClass('play');
}
});
I've enabled the controls for debugging, and if I press 'Play' on the native controls, It then starts working...
Thanks
player[0].play()
? Maybe trigger path is considered by ipad "too long" to be direct user interaction? – dfsq