简体   繁体   English

如何添加 videojs 事件监听器?

[英]How to add videojs event listener?

I add videojs player to my VUE app and I have no idea how to add event listener to it.我将videojs播放器添加到我的 VUE 应用程序中,但我不知道如何向它添加事件侦听器。 I need to track when player starts playing and stop or pause.我需要跟踪播放器何时开始播放并停止或暂停。 I can't find anything related to it, the documentation doesn't provide this.我找不到任何相关的东西,文档没有提供这个。 Here is how my setup looks like according to docs根据文档,这是我的设置的样子

this.player = videojs(this.$refs.videoPlayer, this.options, () => {
    this.player.log('onPlayerReady', this);
})

Alright, this is just好吧,这只是

this.player.on('play', () => {
    this.play()
})
this.player.on('pause', () => {
    this.stop()
})

VideoJS uses the HTML5 <video> element, so you can just use the events associated with that element. VideoJS 使用 HTML5 <video>元素,因此您可以只使用与该元素关联的事件

Example:例子:

 document.querySelector(".video").addEventListener("play", (e) => { console.log("playing..."); }); document.querySelector(".video").addEventListener("pause", (e) => { console.log("paused..."); });
 <link href="https://vjs.zencdn.net/7.20.1/video-js.css" rel="stylesheet" /> <script src="https://vjs.zencdn.net/7.20.1/video.min.js"></script> <video class="video-js video" controls preload="auto" width="640" height="268" data-setup='{ "playbackRates": [0.5, 1, 1.5, 2],"loopbutton": true }'> <source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'> <source src="http://vjs.zencdn.net/v/oceans.webm" type='video/webm'> </video>

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

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