Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get Video.js plugin to work

I'm able to get Video.JS working but I'm not able to get the Resolution Switcher plugin working.

I just don't know where to put the code to get it work I think

I put this in my <head>

<link href="http://vjs.zencdn.net/5.4.4/video-js.css" rel="stylesheet">
<!-- If you'd like to support IE8 -->
<script src="http://vjs.zencdn.net/ie8/1.1.1/videojs-ie8.min.js"></script>

I'm using this code for where the video will be displayed

<video id='video' class="video-js vjs-default-skin"></video>

I put this right before my <body> ends

<script src="http://vjs.zencdn.net/5.4.4/video.js"></script>
<script src="assets/js/video.js"></script>
<script src="assets/js/videojs-resolution-switcher.js"></script>

And this is placed afterwards

videojs('video', {
    controls: true,
    plugins: {
        videoJsResolutionSwitcher: {
            default: 'high',
            dynamicLabel: true
        }
    }
}, function() {

    // Add dynamically sources via updateSrc method 
    player.updateSrc([{
        src: 'videos/intros/Intro480_30_Condensed.mp4',
        type: 'video/mp4',
        label: '480'
    }, {
        src: 'videos/intros/Intro720_30_Condensed.mp4',
        type: 'video/mp4',
        label: '720'
    }])

    player.on('resolutionchange', function() {
        console.info('Source changed to %s', player.src())
    })

})

And this is the error I get in the console

enter image description here

and nothing is playing.

like image 921
CodingIsHardForMe Avatar asked Sep 06 '25 18:09

CodingIsHardForMe


1 Answers

According to the code posted on their github, the first line should be:

var player = videojs('video', {

And probably, into the callback function, instead of referring to player, you can just use this.

var player = videojs('video', {
    controls: true,
    plugins: {
        videoJsResolutionSwitcher: {
            default: 'high',
            dynamicLabel: true
        }
    }
}, function() {

    // Add dynamically sources via updateSrc method 
    this.updateSrc([{
        src: 'videos/intros/Intro480_30_Condensed.mp4',
        type: 'video/mp4',
        label: '480'
    }, {
        src: 'videos/intros/Intro720_30_Condensed.mp4',
        type: 'video/mp4',
        label: '720'
    }])

    this.on('resolutionchange', function() {
        console.info('Source changed to %s', this.src())
    })

})
like image 148
Aᴍɪʀ Avatar answered Sep 08 '25 08:09

Aᴍɪʀ