Replies: 15 comments 1 reply
-
I have the exact same issue. I've found that this only occurs with nested functions. Given the time between updates on this project, I don't have much fate in this being resolved anytime soon. Therefore, a workaround is putting the player directly in the return statement in the export default function of a certain page. I'm using Next.js (which has a React-based front-end), and this seems to work. However, it's still a bug. I'd like to hear from someone about a solution that isn't a workaround like this! Edit: by putting the player directly in the return statement of a default function, I mean the literal component. |
Beta Was this translation helpful? Give feedback.
-
This has to be due to the lack of memoization. Any state updates will cause the player to re-render. Using refs to control playback wouldn't have had this effect. In using functional components to toggle the prop passed to the player element, we'll probably want to use memoization to make sure the player only re-renders when significant pieces of state change. I'm looking into this now, and it may be that there will need to be changes to the react player api itself, or it could be just an implementation detail. |
Beta Was this translation helpful? Give feedback.
-
can you also let me know which player you guys are using? |
Beta Was this translation helpful? Give feedback.
-
For me, it ended up being cleaner to just have a one return statement with some conditional rendering inside. That also solved the problem of it flickering because it was inside a nested function's return statement. I'm using react-player to play video files stored in a GCP storage bucket currently. I'm using the useState React hook for states like playing, started, progress etc. |
Beta Was this translation helpful? Give feedback.
-
Notice the flickering stops when you change I can take a closer look when I get more time. Spare time is not something I have much of at the moment. |
Beta Was this translation helpful? Give feedback.
-
@LongLiveCHIEF we were upgrading to the same version in the example 2.9.0 and using the file player. |
Beta Was this translation helpful? Give feedback.
-
My FT job is working with this quite a bit ATM, and this is one that falls in scope, so I can def help. It seems like we can update the title of this one to indicate only the file player is affected?
In this case, then we can advise user to use const sourceFiles = ['file.mp4', 'another.mp4']
const files = useMemo(() => {[...sourceFiles]}, [sourceFiles])
return (
<>
<ReactPlayer
url={files}
/>
</>
) |
Beta Was this translation helpful? Give feedback.
-
Yep, or just tell ReactPlayer not to re-render or reload if the |
Beta Was this translation helpful? Give feedback.
-
I might be missing something here, but my url prop was literally just url="fileurl.mp4". It had nothing to do with an array and the player would still immediately flicker upon preloading. |
Beta Was this translation helpful? Give feedback.
-
@wouter-deen If you can create something that reproduces the issue, I can take a look. |
Beta Was this translation helpful? Give feedback.
-
I rewrote my code to use conditional rendering, hence fixing the issue. I don't have any code sample, but I think it had to do with the fact that I used the useState hook to save playing, volume, pip, timestamp etc. states. For anyone having this issue, I suggest you try to do what I said in my first comment in this thread. If that doesn't resolve the issue, I suggest you work out what the issue is by simply eliminating certain parts (like hooks, fetching the last timestamp from your database etc.) until the problem doesn't pop up. |
Beta Was this translation helpful? Give feedback.
-
@wouter-deen Can you be more about how you solved it? any other solutions? |
Beta Was this translation helpful? Give feedback.
-
@ferrero1987 Do you have a reproducible example of this happening? Does anyone? |
Beta Was this translation helpful? Give feedback.
-
For me the issue was that I called |
Beta Was this translation helpful? Give feedback.
-
It can also be caused if you pass a closure (lambda/anonymous function defined locally in your wrapper) to the wrapper argument of |
Beta Was this translation helpful? Give feedback.
-
Current Behavior
v2 - Using hooks along with state within onProgress callback creates a re-render loop. Player flickers endlessly.
Expected Behavior
Setting a separate piece of state that the player is not dependent on should not re render ReactPlayer
Steps to Reproduce
const [played, setPlayed] = React.useState(false);
onProgress={handleProgress}
Example provided:
Uncomment
setPlayed
inside handleProgress to see issuehttps://codesandbox.io/s/strange-sun-cw9oq?file=/src/App.js:301-311
Environment
Other Information
If we convert this to a class component or revert to v1 the issue is not present. Also state must be set to the passed value on the progress handler (using a static value to set state does not cause flicker)
Beta Was this translation helpful? Give feedback.
All reactions