Detect If `pause` Event Fired By User Interaction Or Buffer Underrun? March 31, 2023 Post a Comment When playing a live audio stream, like web radio, through or Audio(), the pause event can fire in (at least) three ways: user clicks on the pause button (with Solution 1: The waiting event should fit your needs. You can try this demo while you simulate bad network with the dropdown in Chrome's Network tab (e.g: Slow 3G) const video = document.getElementById('mwe_player_0'); video.onwaiting = function() { console.log('onwaiting'); };Copy <video id="mwe_player_0" controls="" preload="none" style="width:800px;height:450px"><source src="https://upload.wikimedia.org/wikipedia/commons/2/22/Volcano_Lava_Sample.webm" type="video/webm; codecs="vp8, vorbis""></video>Copy Note that this demo works with HTMLAudioElement as well (because it inherits HTMLMediaElement). The video demo is just easier to test. Solution 2: If you want to start an event when the user pauses the audio then this snippet will do the job. I didn't test it on mobile in the notification drawer but I think it'll work. const video = document.querySelector('video'); video.addEventListener('pause', (event) => { console.log('The Boolean paused property is now true. Either the ' + 'pause() method was called or the autoplay attribute was toggled.'); }); Copy resource: audio element events resource: pause event I also found a helpful answer to what you are trying to do 2 (at least from what I understand) and why it's a bad technique. Link to question 3 Events: stalled / waiting check the events resource Share Post a Comment for "Detect If `pause` Event Fired By User Interaction Or Buffer Underrun?"
Post a Comment for "Detect If