jsmpeg icon indicating copy to clipboard operation
jsmpeg copied to clipboard

Safari 12.0 on Mac OS X also requires web audio unlocking

Open stondbringa opened this issue 6 years ago • 1 comments

on Safari 12.0, the audio context is in "suspended" state by default, and requires a click to be resumed:


var context = new AudioContext();

console.log('context state:', context.state);

var unlock = function() {
	context.resume().then(function()
	{
	    console.log("context resumed");
	});	
};

document.body.addEventListener('click', unlock, false);

(With the help of: https://hackernoon.com/unlocking-web-audio-the-smarter-way-8858218c0e09)

So I guess that the needsUnlocking method should be updated according to the initial state of the context and not only based on UA? https://github.com/phoboslab/jsmpeg/blob/000bd2f6438b936862a36eb7c20c2dbd2e547e4a/src/webaudio.js#L132

Based on the player.audioOut.unlocked being false, we could implement our own logic (via an unmute button) to unlock the web audio on any device.

Thanks

stondbringa avatar Dec 12 '18 10:12 stondbringa

Chrome 96.0.4664.110 on mac OS 12.1: https://jsmpeg.com/perf.html?file=blade-runner-2049-240p.ts&webgl=1&wasm=1&audio=1 => The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page.

So it seems that all browsers now would need the audio unlocking feature

stondbringa avatar Jan 06 '22 16:01 stondbringa