Giter Site home page Giter Site logo

Comments (8)

redxtech avatar redxtech commented on July 19, 2024

I can probably watch the instance for events and them emit those.
Would that work?

from vue-plyr.

jwjcmw avatar jwjcmw commented on July 19, 2024

That would probably work, and would be the more "vue" way of doing it. I'm not sure how much extra overhead that extra layer adds on...I'm monitoring the time change, so there is going to be a whole lot of emitting going on.

from vue-plyr.

jwjcmw avatar jwjcmw commented on July 19, 2024

How about something like this, where you can pass in the events that you want emitted back...

<plyr :emit="['timeupdate','exitfullscreen']" @timeupdate="videoTimeUpdated" @exitfullscreen="exitedFullScreen">

and then the plyr component will just emit what has been requested...

<script>
  import plyr from 'plyr'
  import 'plyr/dist/plyr.css'

  export default {
    name: 'plyr',
    props: {
      /** Options object for plyr config. */
      options: {
        type: Object,
        required: false,
        default () { return {} }
      },
      /**new prop to accept what to emit back**/
      emit: {
          type: Array,
          required: false,
          default () { return [] }
      },
    },
    data () {
      return {
        player: {}
      }
    },
    mounted () {
      this.player = plyr.setup(document.getElementById(`plyr-container-${this.idNumber}`),
        this.options)[0]
      /**after player object is setup, loop through the emit array to set the on() API method for each**/
      this.emit.forEach(element => {
        this.player.on(element,this.emitPlayerEvent)
      });
    },
    methods: {
        /**method to handle emitting any of the player events**/
        emitPlayerEvent() {
            this.$emit(event.type,event)
        }, 
    }, 
    beforeDestroy () {
      this.player.destroy()
    },
    computed: {
      idNumber () {
        return Math.floor(Math.random() * (100000 - 1)) + 1
      }
    }
  }
</script>

If you like this method, I can set it up in each of the plyr-* components and create a PR.

from vue-plyr.

redxtech avatar redxtech commented on July 19, 2024

That looks great!
I wouldn't be able to get to this for a bit, so if you're willing to send a PR that would be amazing !

from vue-plyr.

jwjcmw avatar jwjcmw commented on July 19, 2024

Will do.

from vue-plyr.

jwjcmw avatar jwjcmw commented on July 19, 2024

#5

from vue-plyr.

redxtech avatar redxtech commented on July 19, 2024

Accepted PR, should be good.

from vue-plyr.

rulrok avatar rulrok commented on July 19, 2024

@redxtech @jwjcmw Heads up!
The line:

this.player.on(element,this.emitPlayerEvent)

off is never called

this.player.off(...).

This causes memory leaks.

I'm just not sure if it it necessary this part of the code only, or some bug with plyr also.
On my SPA I cannot use any event with :emit because of the code I highlighted.

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.