Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use on Vue #4167

Closed
HadiChen opened this issue Mar 7, 2017 · 9 comments
Closed

How to use on Vue #4167

HadiChen opened this issue Mar 7, 2017 · 9 comments

Comments

@HadiChen
Copy link

HadiChen commented Mar 7, 2017

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

@Logic-Punch
Copy link

Logic-Punch commented Mar 26, 2017

Working fine for me?

@edouard-lopez
Copy link

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

@Logic-Punch
Copy link

@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>

@edouard-lopez
Copy link

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

@Logic-Punch
Copy link

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

@gkatsev
Copy link
Member

gkatsev commented Jan 2, 2018

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

@gkatsev
Copy link
Member

gkatsev commented Jan 30, 2018

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!

@gkatsev gkatsev closed this as completed Jan 30, 2018
@chopfitzroy
Copy link
Contributor

PR submitted #5899.

@gkatsev
Copy link
Member

gkatsev commented Mar 28, 2019

Thanks @CrashyBang!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants