With multiple players, force only one player to be playing
See original GitHub issueAfter 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:
- Created 5 years ago
- Reactions:2
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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>
, passplaying={false}
(or just not pass a playingprop
) 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.