Giter Site home page Giter Site logo

Comments (10)

redxtech avatar redxtech commented on July 19, 2024 3

That seems like a reasonable solution. I can probably build that into the next release to fix this sort of issue.

from vue-plyr.

redxtech avatar redxtech commented on July 19, 2024 3

I think that using nextTick to access the ref is the best solution for now. If anyone has any other questions feel free to open a new issue.

from vue-plyr.

kennybuc avatar kennybuc commented on July 19, 2024 3

I think that using nextTick to access the ref is the best solution for now. If anyone has any other questions feel free to open a new issue.

This does not work for me. The player is still undefined.

from vue-plyr.

jacobedawson avatar jacobedawson commented on July 19, 2024 2

From what I understand, it's not best practice to 1.) use refs to access child components and 2.) depend on refs being available in computed properties: https://vuejs.org/v2/guide/components-edge-cases.html#Accessing-Child-Component-Instances-amp-Child-Elements

That might have something to do with it - I've found that refs is not even available in the mounted hook on the first render, so Nuxt might be having an issue with that. I still haven't worked out the best way to grab a reference to the player instance.

from vue-plyr.

 avatar commented on July 19, 2024

@jacobedawson: Thanks for the answer. It's in the same component and I'm following the doc

The goal is to play the player programmatically

from vue-plyr.

kjetilge avatar kjetilge commented on July 19, 2024

I'm having the same problem in Vue SPA. This is what I had to do to initialize the player with a video:

<template>

  <vue-plyr ref="plyr" id="video-player">
    <video controls>
      <source src type="video/mp4"/>
    </video>
  </vue-plyr>

</template>
<script>
  export default {
    data () {
      return {
        player: {},
        playerInitialized: false
      }
    },
    updated: function () {
      // INITIALIZE PLYR PLAYER WITH A VIDEO
      this.$nextTick(function () {
        const videoplayer = document.getElementById("video-player");
        if(!this.playerInitialized) { // If player not initialized
          videoplayer.addEventListener('ready', event => {
            this.playerInitialized = true
            this.player = this.$refs.plyr.player

            if(!this.player.source) {
              this.player.source = {
                type: 'video',
                title: 'Example title',
                sources: [{
                  src: "example-video-url.mp4",
                  type: 'video/mp4',
                  size: 1080,
                }]
              }
            }
          })
        }
      }),
    methods: {
      // Load videos programatically
      loadVideo (videoUrl) {
        this.player.source = {
          type: 'video',
          title: 'Example title',
          sources: [{
            src: videoUrl,
            type: 'video/mp4',
            size: 1080,
          }]
        }
      }
    }
    }
  </script>

If any one knows how to do this in a better way, please let me know.

from vue-plyr.

rafaelacb avatar rafaelacb commented on July 19, 2024

Hi, is there any solution for this??

from vue-plyr.

redxtech avatar redxtech commented on July 19, 2024

@rafaelacb (and others):
Sorry for the delays, I've been swamped. I should be completely free to look at this in a few weeks.
I appreciate your understanding.

from vue-plyr.

mangowi avatar mangowi commented on July 19, 2024

Hi!, @rafaelacb and everyone.

How did you guys solve this issue?

Thank you in advance :)

from vue-plyr.

Vusal317 avatar Vusal317 commented on July 19, 2024

This is work for me
await this.$nextTick(() => {
setTimeout(() => {
console.log(this.$refs.plyr.player)
}, 500)
});

from vue-plyr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.