sd1sd1
sd1sd1

Reputation: 1048

play mp3 files with safari or chrome in ios or android

i try to preload audio html5 tag and then play the files one by one. on a desktop computer that seems to work but on my iphone 4 or 5 with safari or chrome browser - the sounds does not play.

my sounds are mp3, but i also tried with mp

this is my html:

<html>
<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>




    <script>    
    $(function(){
        banner_array = [];
        banner_array.push({
            "audio": 'dis1_1'
        });
        banner_array.push({
            "audio": 'dis1_2'
        });
        banner_array.push({
            "audio": 'dis2_1'
        });
        banner_array.push({
            "audio": 'dis2_2'
        });
        banner_array.push({
            "audio": 'dis3_1'
        });
        banner_array.push({
            "audio": 'dis3_2',
        });

        $.each(banner_array,function(a,b){
            setTimeout(function() {$("."+b.audio)[0].play();},25000);
    });
});
    </script>
  </head>
  <body>
    <audio hidden name="media"  class="dis1_1"><source src="/templates/t4807/audio/dis1_1.mp3" type="audio/mp3"></audio>
    <audio hidden name="media"  class="dis1_2"><source src="/templates/t4807/audio/dis1_2.mp3" type="audio/mp3"></audio>
    <audio hidden name="media"  class="dis2_1"><source src="/templates/t4807/audio/dis2_1.mp3" type="audio/mp3"></audio>
    <audio hidden name="media"  class="dis2_2"><source src="/templates/t4807/audio/dis2_2.mp3" type="audio/mp3"></audio>
    <audio hidden name="media"  class="dis3_1"><source src="/templates/t4807/audio/dis3_1.mp3" type="audio/mp3"></audio>
    <audio hidden name="media"  class="dis3_2"><source src="/templates/t4807/audio/dis3_2.mp3" type="audio/mp3"></audio>
  </body>
</html>

any help shall be greatly appriciated

Upvotes: 1

Views: 3707

Answers (1)

Bamsworld
Bamsworld

Reputation: 5680

iOS does not allow for this -

Note: On iOS, the Web Audio API requires sounds to be triggered from an explicit user action, such as a tap.

The above exert is taken from the Safari HTML5 Audio and Video Guide

Upvotes: 1

Related Questions