Not able to access player.currentTime() of VideoJS

Viewed 342

I am trying to access the current time of videojs in the method other that where I initialised it. But I am not able to access it. It says "cannot read property currentTime of undefined"

This is what I am trying to do

I initialize player in below function

 initVideoJS = ()=> {
        var that = this;
        debug('Init VideoJS')
        const options = {
            fluid: true,
            preload: false,
            autoplay: false,
            controls: true,
            aspectRatio: "16:9"
        }

       player = this.video =  videojs(this.video_el, options)   //player is the global variable 
        that.setState({player:this.video})
        this.video.on("timeupdate", () => {
            currentTime = this.video.currentTime();
            duration = this.video.duration()


    }

This is where I am trying to access currentTime of player

jumpToSpecificMarker= (time) =>{
        // this.state.player.currentTime(10)
       player.currentTime()
    }

I am invoking jumpToSpecificMarker from my render method like this

 render() {
        if (this.props.sentance_selected_reducer.flag) {
            console.log("Inside if flag")

            this.jumpToSpecificMarker(player, this.props.sentance_selected_reducer.sentanceTime);
        }
1 Answers

player variable is out of the scope of your function jumpToSpecificMarker.

How are you invoking jumpToSpecificMarker? Can you also pass player as parameter to jumpToSpecificMarker(player, time)?

Related