I use videojs within vue component, it works fine. Then I tried to use videojs-hotkeys plugin like
<template>
<video
id="myplayer"
poster="xxx.jpg"
class="video-js"
controls>
<source :src="source.src" :type="source.type">
</video>
</template>
<script>
import $ from 'jquery';
import videojs from 'video.js';
$(function(){
console.log(this); //Output: object: #document
});
export default{
data(){
return {
source: {
src:"xxx.mp4",
type:""
}
}
},
mounted() {
console.log(this); //Output: Vue Component: vue instance
//import external script
let hotkeysScript = document.createElement('script')
hotkeysScript.setAttribute('src', 'http://cdn.sc.gl/videojs-hotkeys/latest/videojs.hotkeys.min.js')
document.head.appendChild(hotkeysScript)
videojs('myplayer').ready(function () {
console.log(this); //Output: player instance
this.hotkeys({ //Error: this.hotkeys is not a function
volumeStep: 0.1,
seekStep: 5,
enableModifiersForNumbers: false
});
})
}
}
</script>
The browser gave me below error information
app.js:107959 Uncaught TypeError: this.hotkeys is not a function
at Player.<anonymous> (app.js:107959)
at Player.<anonymous> (app.js:16325)
at Array.forEach (<anonymous>)
at Player.<anonymous> (app.js:16324)
at bound (app.js:14739)
at app.js:16992
I tried to print the value of "this" in code(please see the comment in code), and gives output for your reference. Please help. Thanks so much.