New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subtitles never loaded with Firefox #490
Comments
FYI, I think the issue is with how react add/remove text tracks... In a prototype I've been able to fix the issue by managing tracks through the dom: If you look to the code below, you'll see that I'm not relying on render method to add tracks, but do the job in onLoadedMetadata: onLoadedMetadata = (e: SyntheticEvent<HTMLVideoElement>) => {
const video = e.currentTarget;
// As a workaround for Firefox, let's remove old tracks
// before adding the new ones. Letting react do
// the job does not seems to work properly
const oldTracks = video.querySelectorAll('track');
oldTracks.forEach((oldTrack) => {
video.removeChild(oldTrack);
});
if (this.props.tracks) {
this.props.tracks.map((t, trackIdx) => {
const track = document.createElement('track');
track.kind = t.kind!;
track.label = t.label!;
track.srclang = t.srcLang!;
track.default = t.default!;
track.src = t.src!;
track.addEventListener('error', (e: Event) => {
console.warn(`Cannot load track ${t.src!}`)
});
track.addEventListener('load', (e: Event) => {
const textTrack = e.currentTarget as HTMLTrackElement;
if (t.default === true) {
textTrack.track.mode = 'showing';
video.textTracks[trackIdx].mode = 'showing'; // thanks Firefox
} else {
textTrack.track.mode = 'hidden';
video.textTracks[trackIdx].mode = 'hidden'; // thanks Firefox
}
});
video.appendChild(track);
});
}
};
render() {
const {
srcs,
tracks,
// Just to omit those props
playbackRate,
// onEnded,
...mediaProps
} = this.props;
const key = srcs && srcs.length > 0 ? srcs[0].src : '';
return (
<video
style={{width: '100%', height: '100%'}}
onLoadedMetadata={this.onLoadedMetadata}
ref={this.videoRef}
{...mediaProps}
{...(this.props.playsInline ? { 'webkit-playsinline': 'webkit-playsinline' } : {})}
>
{srcs && srcs.map((s, idx) => <source key={`${s.src}-${idx}`} {...s} />)}
{/*
// This would be so easy, but subsequent changes in tracks will
// be ignored by firefox. See the workaround onLoadedMetaData function
{tracks && tracks.map((t, idx) => {
return null;
return (
<track id={`${t.src}-${idx}`} key={`${t.src}-${idx}`} {...t}/>
);
})}
*/}
</video>
);
} @cookpete, I can add this behaviour to react-player. But I'm not sure it's a nice addition, looks ugly hack and will only be useful for some people. What do you think ? |
@belgattitude I haven't looked too closely at this yet but I did spot this:
Have you tried ensuring that the first track element has |
I've tested the player with first track element which has |
Same issue here, subtitles work perfectly on chrome, but don't show up at all on Firefox... |
The solution proposed by @belgattitude works for me. export default function onLoadedMetadata(e) {
const video = e.currentTarget;
const oldTracks = video.querySelectorAll('track');
for (const track of oldTracks) {
track.remove();
}
if (this.state.config.file.tracks) {
this.state.config.file.tracks.map((t, trackIdx) => {
const track = document.createElement('track');
track.kind = t.kind;
track.label = t.label;
track.srclang = t.srcLang;
track.default = t.default;
track.src = t.src;
track.addEventListener('load', e => {
const textTrack = e.currentTarget;
if (t.default === true) {
textTrack.track.mode = 'showing';
video.textTracks[trackIdx].mode = 'showing'; // thanks Firefox
} else {
textTrack.track.mode = 'hidden';
video.textTracks[trackIdx].mode = 'hidden'; // thanks Firefox
}
});
const video = document.querySelector('video');
video.appendChild(track);
});
}
} |
@arkadiusz-wieczorek, @jerlam06 Before using the workaround, could one of you test with the Due to some rush I had rewrite my own player so I cannot test right now... but be warned my workaround was not sufficient for all situations. Debugging was a long long long road... ;) Tell me and when I have time I'l send a gist with few discoveries I've made. Can be useful |
This seems like a problem with React and/or Firefox, and not really with ReactPlayer. The workarounds are impressive but not something I really want to include in the library, especially if:
You can pass through your own Is it worth opening a ticket with React and/or Firefox to try and gain some more wisdom? |
dear @cookpete
Spent few hours trying to debug why firefox does not display (load) my subtitles, while chrome was doing it right.I would be grateful if you could confirm or help.
Here's an example:
https://soluble.io/react-player/demo-bugtracks/
I've been thinking about a firefox bug, but I'm not sure.. so I wrote a basic video player and it worked quite well:
https://gist.github.com/belgattitude/26d00cbd33df56567845b5a76f265a0b
Can you help ?
The text was updated successfully, but these errors were encountered: