Video.js: How to use on Vue

Created on 7 Mar 2017  路  9Comments  路  Source: videojs/video.js

I have been unable to use vue, I hope to be a document

Most helpful comment

@edouard-lopez
Here is an example of everything I use.
Yes everything can be dynamic if you want.

<template>
    <video playsinline id="myPlayer" class="video-js vjs-default-skin" width="100%" controls preload="auto" data-setup='{ "aspectRatio":"16:9" }'></video>
</template>

<script>
    window.videojs = require('video.js');

    export default {
        data(){
            return{
                player: '',
                url: 'https://someurl.com',
                volume: 1
            };
        },
        methods: {
            playerInitialize(){ 
                this.player = videojs('myPlayer'); 
            },
            playerDispose(){ 
                this.player.dispose(); 
            },

            playerPlay(){
                this.player.play();
            },
            playerPause(){
                this.player.pause();
            },


            playerSetSrc(url){ 
                this.player.src(url); 
            },
            playerSetVolume(float){
                this.player.volume(float); 
            },
            playerSetPoster(url){ 
                this.player.poster(url); 
            },
            playerSetTime(time){
                this.player.currentTime(time);
            },


            playerEventEnded(){
                console.log('ended');
            },
            playerEventVolume(){ 
                this.volume = this.player.volume(); 
            },
            playerEventError(){ 
                console.log( this.playerGetError() )
            },


            playerGetPaused(){
                return this.player.paused();
            },
            playerGetTime(){
                return this.player.currentTime();
            },
            playerGetError(){
                return this.player.error().message;
            },


            playerSetupEvents(){
                this.player.on('ended', function(){ var a = window.playerEvents.playerEventEnded(); });
                this.player.on('volumechange', function(){ window.playerEvents.playerEventVolume(); });
                this.player.on('error', function(){ window.playerEvents.playerEventError(); });
            },
        },
        mounted(){
            window.playerEvents = this;
            this.playerInitialize();
            this.playerSetSrc(this.url);
            this.playerSetupEvents();
        },
        beforeDestroy() { 
            this.playerDispose(); 
        }
    }
</script>

All 9 comments

Working fine for me?

@Adynnor can you paste some snippet to show how you did it? Do you know how to change video dynamically?

@edouard-lopez
Here is an example of everything I use.
Yes everything can be dynamic if you want.

<template>
    <video playsinline id="myPlayer" class="video-js vjs-default-skin" width="100%" controls preload="auto" data-setup='{ "aspectRatio":"16:9" }'></video>
</template>

<script>
    window.videojs = require('video.js');

    export default {
        data(){
            return{
                player: '',
                url: 'https://someurl.com',
                volume: 1
            };
        },
        methods: {
            playerInitialize(){ 
                this.player = videojs('myPlayer'); 
            },
            playerDispose(){ 
                this.player.dispose(); 
            },

            playerPlay(){
                this.player.play();
            },
            playerPause(){
                this.player.pause();
            },


            playerSetSrc(url){ 
                this.player.src(url); 
            },
            playerSetVolume(float){
                this.player.volume(float); 
            },
            playerSetPoster(url){ 
                this.player.poster(url); 
            },
            playerSetTime(time){
                this.player.currentTime(time);
            },


            playerEventEnded(){
                console.log('ended');
            },
            playerEventVolume(){ 
                this.volume = this.player.volume(); 
            },
            playerEventError(){ 
                console.log( this.playerGetError() )
            },


            playerGetPaused(){
                return this.player.paused();
            },
            playerGetTime(){
                return this.player.currentTime();
            },
            playerGetError(){
                return this.player.error().message;
            },


            playerSetupEvents(){
                this.player.on('ended', function(){ var a = window.playerEvents.playerEventEnded(); });
                this.player.on('volumechange', function(){ window.playerEvents.playerEventVolume(); });
                this.player.on('error', function(){ window.playerEvents.playerEventError(); });
            },
        },
        mounted(){
            window.playerEvents = this;
            this.playerInitialize();
            this.playerSetSrc(this.url);
            this.playerSetupEvents();
        },
        beforeDestroy() { 
            this.playerDispose(); 
        }
    }
</script>

@Adynnor gee, I was missing the this.player.src(url); !
Thanks

@edouard-lopez NP, glad you worked it out! :)

@Adynnor would you be able to write a quick doc about using video.js with vue similar to our react doc?

Closing this as it's been answered. If anyone wants to submit a PR to make a doc like the react doc, that would be awesome!

PR submitted #5899.

Thanks @CrashyBang!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gfviegas picture gfviegas  路  3Comments

SolmazKh picture SolmazKh  路  4Comments

askaliuk picture askaliuk  路  3Comments

dingyaguang117 picture dingyaguang117  路  4Comments

0xsven picture 0xsven  路  3Comments