question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

With multiple players, force only one player to be playing

See original GitHub issue

After going through many plugins, this is the best media player for React I’ve found so thank you!

I’m using this just for audio with the File player type. I have a playlist which is just a list of multiple <ReactPlayer /> elements and I’d like to force it to only play one player at a time. Thus, if a player is playing and you press play on another player, then the first player stops. Currently, it will play any and all players simultaneously.

Looking through all of the issues I couldn’t find a reference to this so my apologies if this is a duplicate.

How can I force only one player to play on the page at any given time?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

3reactions
superbuggycommented, Aug 24, 2018

In the container component holding all your <ReactPlayer>s components, you would have to keep track of which player is playing. You could possibly use array indexes as ids for your child <ReactPlayer>s, if you’re not doing anything to the array that would change the order of the child <ReactPlayer>.

The <PlayerContainer> component should have a method for changing its state that keeps track of the id of the currently playing <ReactPlayer>, pass playing={false} (or just not pass a playing prop) to every other child after state changes.

You’d pass this method as the onPlay to each <ReactPlayer> also.

Does that make sense?

0reactions
t-lochheadcommented, Sep 14, 2020

In the container component holding all your <ReactPlayer>s components, you would have to keep track of which player is playing. You could possibly use array indexes as ids for your child <ReactPlayer>s, if you’re not doing anything to the array that would change the order of the child <ReactPlayer>.

The <PlayerContainer> component should have a method for changing its state that keeps track of the id of the currently playing <ReactPlayer>, pass playing={false} (or just not pass a playing prop) to every other child after state changes.

You’d pass this method as the onPlay to each <ReactPlayer> also.

Does that make sense?

I tried this solution but ran into a problem: ReactPlayer doesn’t seem to register a state change through the YouTube iframe. Has anyone else solved this issue? It seems to not be a problem on mobile for some reason.

Read more comments on GitHub >

github_iconTop Results From Across the Web

With multiple players, force only one player to be playing #215
Thus, if a player is playing and you press play on another player, then the first player should stops. Currently, it will play...
Read more >
With multiple audio players in React, pause all but currently ...
What I need to do is pause all other <AudioPlayer /> components except the one that is currently playing. Otherwise, you can play...
Read more >
How to Play 2 Player Coop Games on Nintendo Switch (Joy ...
Do you want to know how to play 2 player coop games on Nintendo Switch with one Joy Con Controller? On the home...
Read more >
I Doubt It - card game rules - Pagat.com
There can be three or more players - probably no more than six. It is possible for two to play, but then the...
Read more >
Are there any media players that will play multiple audio tracks ...
I don't want to merge it, I don't want to watch it in an editor. I just need a media player capable of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found