mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
webaudio: unlock audio context on user interaction
This commit is contained in:
+20
@@ -31613,6 +31613,26 @@ static ma_result ma_context_init__webaudio(ma_context* pContext, const ma_contex
|
||||
miniaudio.get_device_by_index = function(deviceIndex) {
|
||||
return miniaudio.devices[deviceIndex];
|
||||
};
|
||||
|
||||
miniaudio.unlock_event_types = (function(){
|
||||
return ['touchstart', 'touchend', 'click'];
|
||||
})();
|
||||
|
||||
miniaudio.unlock = function() {
|
||||
for(var i = 0; i < miniaudio.devices.length; ++i) {
|
||||
var device = miniaudio.devices[i];
|
||||
if (device != null && device.webaudio != null) {
|
||||
device.webaudio.resume();
|
||||
}
|
||||
}
|
||||
miniaudio.unlock_event_types.map(function(event_type) {
|
||||
document.removeEventListener(event_type, miniaudio.unlock, true);
|
||||
});
|
||||
};
|
||||
|
||||
miniaudio.unlock_event_types.map(function(event_type) {
|
||||
document.addEventListener(event_type, miniaudio.unlock, true);
|
||||
});
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user