检测音频是否在网站上播放
这在某种程度上是这个问题的重复性不了解如何使用接受的答案。此外,这个问题很旧,也许现在有一种更好的方法。
我的用例:
我想测试一般是否与剧作家一起演奏音频。音频源不是DOM元素,因此检查媒体元素不是解决方案。
这就是代码的使用方式:
const isAudioPlaying = page.evaluate(() => {
/* Code goes here */
})
编辑: 这就是媒体播放的代码在其最简单的形式中的样子:
function createAudioPlayer() {
const audio = new Audio()
return {
setSource: (src) => audio.src = src,
play: () => audio.play,
pause: () => audio.pause,
resume: () => audio.resume,
}
}
该工厂仅将默认的音频构造函数用于播放。它永远不会像那样接触DOM。
This is somewhat a duplicate of this question, but I do not understand on how to use the accepted answer. Furthermore the question is quite old and maybe there is a better way available now.
My use case:
I want to test if audio in general is playing with Playwright. The audio source is not a DOM-Element, so checking media elements is not a solution.
This is how the code would get used:
const isAudioPlaying = page.evaluate(() => {
/* Code goes here */
})
Edit:
And this is how the code of the media playback looks like in its most simple form:
function createAudioPlayer() {
const audio = new Audio()
return {
setSource: (src) => audio.src = src,
play: () => audio.play,
pause: () => audio.pause,
resume: () => audio.resume,
}
}
This factory just uses the default Audio constructor for the playback. It never touches the DOM like that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论