Preload keep playing the first track that was played with it
See original GitHub issueIn the demo/App.js file I created a playlist with urls from the different providers. 2 from youtube, 2 from soundcloud and 2 from vimeo. Like this:
const LINKS = [
'https://www.youtube.com/watch?v=oUFJJNQGwhk'
,'https://www.youtube.com/watch?v=jNgP6d9HraI'
,'https://soundcloud.com/miami-nights-1984/accelerated'
,'https://soundcloud.com/tycho/tycho-awake'
,'https://vimeo.com/90509568'
,'https://vimeo.com/169599296'
]
Along with buttons to switch to the next or previous url.
The 2 first videos play fine. But as soon as it switch to the third one, the provider change and the youtube preload plays the first video in the background. Without any control possible over it.
If I check into the React tree ai can see that the silent video url is a prop of the preload player. But if I check the element tree directly, the youtube iframe points to the first video of the playlist.
I tried to debug this but could not track down the problem.
I pushed my code to my fork github repo if you have time to check it:
https://github.com/SkinyMonkey/react-player/tree/bug-playlist-problem
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (10 by maintainers)
Top GitHub Comments
After some more investigation I think I know the problem.
The order of the players in this array seems to be causing the problem. It seems to only happen when the player is switched with another player in the array of players. The array is keyed using the
displayName
of each player (so components aren’t unmounted/remounted) but it still seems to affect the YT iframe.The YouTube iframe does not do the weird reload error if another player is simply prepending to the array (like if you are preloading YT, SC and Vimeo and then load a Vidme URL). It only happens when you switch from a youtube URL (whilst preloading SC and Vimeo) to a SC or Vimeo URL.
Probably easier with an example:
But it works when you prepend to the array:
A possible fix: sort the player array by key so it is never shuffled (weird but it seems to work)
See https://github.com/CookPete/react-player/commit/c769a7a967f1de83f765b382b8ba3363a6e690f4 from the
fix-preload-bug
branch for an example of a possible fix. If it works I’m happy to use it and update the logic but I would love to know why this is happening.Probably related to this:
From https://github.com/facebook/react/issues/858#issuecomment-32001084
Note that I have (stupidly) just unpublished
1.0.0-beta.4
to try and correct a tagging problem. I have emailed support to try and republish it. I will publish a1.0.0-beta.5
at some point soon anyway. But it’s good to know that this fixes the problem.