资源:暂停事件>我也找到了一个有用的答案,可以帮助您 2 (至少从我的理解)以及为什么这是一种不好的技术.链接到问题 3 事件:已暂停/正在等待检查事件资源When playing a live audio stream, like web radio, through <audio> or Audio(), the pause event can fire in (at least) three ways:user clicks on the pause button (with <audio controls>)user clicks the browsers global audio controlsiOS: Control CenterAndroid: browser's notification drawer (at least Chrome, Opera, Firefox)Desktop: Media Session API controls, but uninitialized, without explicit setActionHandler (might be hidden behind a flag as of now)a buffer underrun caused by various network conditionsIs it possible to distinguish between 1/2 and 3?Ideally, there would be an event property like isTrusted, which I am missingI have tried to guess, looking esp. at readyState and networkState, but both are very inconclusive, especially across browsers (e.g. the interpretation/semantics of HAVE_FUTURE_DATA vs HAVE_ENOUGH_DATA)I have shied away from making a "decaying state machine", juggling other events. A buffer underrun is often preceded by stalled events, and sometimes followed by ended events. A cross-browser implementation seems crazy complex and the danger of false positives very high.Am I out of luck until Media Session lands everywhere?Note: this question looks like a solution, but unfortunately isn't -- browsers handle live streams' "ends" differently and inconsistently. 解决方案 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.');});resource: audio element eventsresource: pause eventI 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 question3 Events: stalled / waiting check the events resource 这篇关于检测&lt; audio&gt;是否用户交互或缓冲区不足触发了"pause"事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-12 15:11