简体   繁体   English

如果 DOM 中不存在视频/音频元素,如何设置 html5 视频/音频的播放速度

[英]How to set playback speed of html5 video/audio if the video/audio element is not present in DOM

How to change the playing speed of videos in HTML5? 如何更改HTML5中视频的播放速度? depicts a way of setting the playback speed of a html5 audio/video element, but the answers given in that question rely on the actual video/audio tag being present in the dom.描述了一种设置 html5 音频/视频元素的播放速度的方法,但该问题中给出的答案取决于 dom 中存在的实际视频/音频标签。 The website - SoundCloud - in particular does not put the audio player in the DOM anywhere, but it still does use it internally.该网站 - SoundCloud - 特别是没有将音频播放器放在 DOM 的任何地方,但它仍然在内部使用它。 Since document.queryselector will not work, how can I set the playback rate?由于 document.queryselector 不起作用,我该如何设置播放速率?

You don't need to actually insert the audio tag into the DOM.您不需要将音频标签实际插入 DOM。

quick example here:这里的快速示例:

document.getElementById('play').addEventListener('click', event => {
    const audio = document.createElement('audio')
  audio.src = "https://www.w3schools.com/html/mov_bbb.mp4"
  audio.play()
})

https://jsfiddle.net/v4ma95L2/ https://jsfiddle.net/v4ma95L2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM