Howler.js: onplayerror not firing (2.1.2)

Created on 4 May 2019  路  4Comments  路  Source: goldfire/howler.js

using the code from the documentation
i can not get onplayerror to fire

with example below / on safari and chrome desktop:
audio play is denied, but onplayerror does not fire
the sound then plays with the first touch/click (onplay is fired)

var sound = new Howl({
    src: ['blank.webm', 'blank.mp3'],
    onplay: function() {
        console.log('audio playing!');
    },
    onplayerror: function() {
        console.log('audio play denied!');
        sound.once('unlock', function() {
            console.log('audio play unlocked!');
        });
    }
});
sound.play();

ps. as playing limitations affect all mayor browsers now,
maybe the error messages could be updated
(line 898 and 917)

Most helpful comment

There is currently no way to detect that the audio is locked. There are some proposals in the works, but the progress seems to be moving slowly. I submitted a bug to Chromium that got marked as wontfix when the promise from a play just hangs if the audio is blocked, which seemed like it would be the logical place to catch in that scenario, rather than just doing nothing.

All 4 comments

this code is a bit clearer,
and i also noticed :

for safari / chrome desktop and safari ios :
this code is enough to unlock audioplay by a click anywhere in the document

for chrome android:
this does not work, i could not get a consistent behaviour on a huawei p20,
but i think the playback must be invoked inside a click/touch event !

an audio file is actually not needed, the Howl needs a format in this case, tough.

as mentioned above, at least on the destop, onplayerror does not get executed

var sound = new Howl({
    src: [''], format: ['mp3'], 
    autoplay: true,
    onplay: function() {
        console.log('audio playing!');
    },
    onplayerror: function() {
        console.log('audio play denied!');
    },
    onunlock: function() {
        console.log('audio play unlocked!');
    },
});

Is anyone addressing this? I can't get onplayerror to fire when Chrome blocks the Audio Context.

There is currently no way to detect that the audio is locked. There are some proposals in the works, but the progress seems to be moving slowly. I submitted a bug to Chromium that got marked as wontfix when the promise from a play just hangs if the audio is blocked, which seemed like it would be the logical place to catch in that scenario, rather than just doing nothing.

Thanks for the detailed answer - appreciate your work. @goldfire

Was this page helpful?
0 / 5 - 0 ratings