1

Im using the following jquery to add HTML5 audio element to an otherwise basic HTML page. I want the audio tag to start playback automatically (the user will navigate to this specific page/area for the explicit purpose of hearing audio stream of a talk show).

It loads and playback starts fine on desktop web browsers and on test android devices, but in ios7 (test device is an iphone 4s), I can see the test alert triggered, but the play status for the audio element doesnt seem to be accessible / responsive at all.

Anyone familiar with a way to set autoplay successfully or to somehow 'trigger' the play status for the audio tag in ios7?

if not, I guess it DOES give me the chance to get the user (mobile device users exclusively) to confirm / acknowledge that they understand the bandwidth implications etc. etc. etc. and have their manual 'click' act as the trigger to start playback.

just thought I'd see if anyone here was familiar with a way to do this in ios7 -- Im not sure if it was also a problem under the previous version of iOS.

Thanks.

heres my code snippet:

$(document).ready(function() {

$('body').append('<audio src="EXTERNAL_AUDIO_STREAM_URL_HERE" autoload="false" autoplay="false" id="audiostream" controls/>');

// THIS WORKS FINE WHEN THIS ELEMENT IS CLICKED IN IOS7 MANUALLY, THE AUDIO STARTS FINE...
$('#startbutton').click(function(){

$('#audiostream')[0].load();
$('#audiostream')[0].play();
alert('loaded, fine...');

});


    // THIS DOES NOT START AUDIO IN IOS7 AUTOMATICALLY...
    setTimeout(function() {
        $('#startbutton').trigger('click');
    }, 2000);



});    
jpop
  • 1,094
  • 1
  • 7
  • 19
tamak
  • 1,541
  • 2
  • 19
  • 39
  • 1
    http://stackoverflow.com/q/4259928/1392379 | [https://developer.apple.com/library/safari/documentation/...](https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html#//apple_ref/doc/uid/TP40009523-CH5-SW4) – ndm Nov 01 '13 at 01:57
  • This was (aside from a short bug in a minor iOS6 revision) never possible, marking as dup. – nietonfir Nov 01 '13 at 20:23

1 Answers1

6

No, its NOT possible on ios...

taken from: Safari Developer Library documentation:
(thanks ndm) [source link is in his comment]

In Safari on iOS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, preload and autoplay are disabled. No data is loaded until the user initiates it. This means the JavaScript play() and load() methods are also inactive until the user initiates playback, unless the play() or load() method is triggered by user action. In other words, a user-initiated Play button works, but an onLoad="play()" event does not.

tamak
  • 1,541
  • 2
  • 19
  • 39