Fix: signal multiple sources change to the browser - #482
Conversation
|
It looks like the "proper" fix for this would be to update the Is it possible that just calling Either way – thanks so much for the amount of effort you've put into this. It's really nice to get such a well-explained issue, complete with a proposed solution. |
Seems to work as expected with Chrome 69 and Firefox 62, and yes this looks better, so I've updated the P/R with the load() method. Thanks.
Ahah... thank you in return ;) BTW, you can test with the latest changes here, I guess it won't really be easy to add proper testing at that level: https://soluble.io/react-player/demo-fixed/ Previous version |
|
For information, this P/R does not yet fix issues with subtitles changes (Firefox)... I was unsure of how to do it in the library, so I did it in my code, see the shouldComponentUpdate(nextProps: VideoPlayerProps, nextState: VideoPlayerState): boolean {
if (nextProps.video.videoId !== this.props.video.videoId) {
if (this.playerRef.current !== null) {
const videoEl = this.playerRef.current!.getInternalPlayer() as HTMLVideoElement;
// Ohoh Firefox, you keep the old subtitles... let's fix that ;)
hideAllSubtitles(videoEl);
// Let's explicitly load the new video :) Till #482 is merged
videoEl.load();
}
return true;
}
// To be tested, a better solution must be found
if (nextProps.activeSubtitleLang !== this.props.activeSubtitleLang) {
const videoEl = this.playerRef.current!.getInternalPlayer() as HTMLVideoElement;
showSubtitle(videoEl, nextProps.activeSubtitleLang || 'en');
return true;
}
return false;
}const hideAllSubtitles = (video: HTMLVideoElement): void => {
for (let i = 0; i < video.textTracks.length; i++) {
console.log('Hidding', video.textTracks[i]);
video.textTracks[i].mode = 'hidden';
console.log('New value', video.textTracks[i]);
}
}
const showSubtitle = (video: HTMLVideoElement, lang: string): void => {
for (let i = 0; i < video.textTracks.length; i++) {
if (video.textTracks[i].language === lang) {
console.log('SHOWING', video.textTracks[i]);
video.textTracks[i].mode = 'showing';
} else {
video.textTracks[i].mode = 'hidden';
}
}
}I keep it for information only.... once I have more time to look at it, I'll make a suggestion. |
|
Nice work @belgattitude. I'm assuming that the |
…rly tested for equality
|
Hi @cookpete, Equality for url's seems to not take arrays into consideration, see the proposal fix: eaaea27. Does it make sense to you ? I've runned into little issue with that. Do you want me to add in a separate P/R or included here (I would love to have it merged before) ? Secondly:
I'm not sure to understand this one... Do you mean you'd prefer to (or we must) implement the Thanks for your time ! |
|
I'm happy to merge this along with the |
Hey @cookpete
I'm building a PWA where I need to be able to load videos from a list. I'm using multiple sources mode (webm/mp4 and multilingual tracks to set videos).
Unfortunately, if the initial loading works, subsequent updates of the sources does not trigger a reload (although the DOM shows updated
<source> and <track>). See my initial ticket : #481. To illustrate the problem switch multiple sources on this demo https://soluble.io/react-player/demo/I thought initially to change the react keys of the sources in
FilePlayer.js:But it's not working.
My solution was to signal / trigger the change by setting
srcObject = nullwhen there's a source change. Both Firefox 61 and Chrome 68 seems to work (using ubuntu 18.04). To be sure it does not produce errors on others browsers, it's encloded in a try/catch...Please let me know if it looks good to you.
Thanks for the great work.