Skip to content

Question: How do I use setters with a ref?  #998

Open
@Johannes5

Description

@Johannes5

Plyr has setters and getters:
image

I would like to use shortcuts to change the playing speed.
According to the above examples, with plyr this would be done with
player.speed = 1.8

But since I am using the forwarded ref from a custom plyr instance I've tried it like this:
image

I've gotten the error message that the left-hand side of the argument is invalid and realized that setting on a ref is pointless

So do I use plyrs setters in my situation?

Activity

realamirhe

realamirhe commented on Nov 26, 2022

@realamirhe
Collaborator

Hey @Johannes5

The speed & volume are attributes that options props received, so you can store them in the state (or ref) conditionally and re-render your component with new speed. Is that solve your problem?

Johannes5

Johannes5 commented on Dec 9, 2022

@Johannes5
Author

image

With the above code I wasn't able to set the speed.

So far I was only able to set the speed inside the useEffect() inside CustomPlyrInstance via
api.plyr.speed = 1.75

Because I want to change the speed via Hotkeys - and I'm using a useHotkeys hook - I need to access this plyr instance outside the useEffect Hook.

Which begs the question - why the useEffect hook in the first place?
And - what can I do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Johannes5@realamirhe

        Issue actions

          Question: How do I use setters with a ref? · Issue #998 · chintan9/plyr-react