jaysalvat / buzz

Buzz is a small but powerful Javascript library that allows you to easily take advantage of the new HTML5 audio element. It tries to degrade silently on non-modern browsers.
http://buzz.jaysalvat.com
MIT License
1.21k stars 227 forks source link

Getting nothing from chrome on android phone #114

Open stccorp opened 7 years ago

stccorp commented 7 years ago

I am getting nothing when using this on Chrome(android phone). It works if I use a desktop browser. It also works perfect on firefox(android phone)

<script>

if (!buzz.isSupported()) {
    alert("Your browser is too old, time to update!");
}

if (!buzz.isOGGSupported()) {
    alert("Your browser doesn't support OGG Format.");
}

if (!buzz.isWAVSupported()) {
    alert("Your browser doesn't support WAV Format.");
}

if (!buzz.isMP3Supported()) {
    alert("Your browser doesn't support MP3 Format.");
}

if (!buzz.isAACSupported()) {
    alert("Your browser doesn't support AAC Format.");
}

var test = new buzz.sound("/assets/alarm2", {
    formats: [ 'ogg', 'mp3' ],
    volume: 100,
    autoplay: false,
    preload: true,
    loop: false
});

test.play();
</script>
jaysalvat commented 7 years ago

Hello.

It sounds like device limitation.

CF. http://buzz.jaysalvat.com/documentation/sound/

"Important: In order to save bandwidth, mobile devices don't load/play sounds without user intervention (no autoplay). iPhone and iPad can only play one sound at a time and don't allow to change the volume dynamically."

githubertus commented 6 years ago

Just verified on Android/Chrome: You need at least 1 confirmation you're willing to hear a sound by clicking an element of your page like <button id="buzz">OK to buzz</button> Staying with your code and having jquery installed this would do the trick

$('#buzz').click(function() {
    test.play();
});
buzzer = setInterval(function() { test.play(); } ,1000 * 5);

Once confirmed this way, subsequent buzzes are allowed to happen programatically.

mouseroot commented 6 years ago

Id like to add to this and confirm that it must be from a button or some other input element, using canvas doesn't work either, I had to rig up a styled button over my canvas to get everything working, but once you get past this limit, the sound will play.

$("#play").on("click",function(){
        $("#c").show();
        var laserSound = new buzz.sound("ACDC.ogg");
        laserSound.play();
});

Because of this I have found a silent mini sound and had that play onload to get the ball rolling.