Skip to content
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

feat(FEC-10160): filter unsupported formats from the configured tracks passed to the receiver #38

Merged
merged 5 commits into from
Jun 28, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(FEC-10160): filter unsupported formats from the configured track…
…s passed to the receiver
  • Loading branch information
yairans committed Jun 28, 2020
commit 92dcbac1f2f0b3ef1928302d2449d2459ae64331
28 changes: 18 additions & 10 deletions src/cast-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -877,17 +877,25 @@ class CastPlayer extends BaseRemotePlayer {
loadOptions.media.breaks = breaks;
}
}
if (this._playerConfig.sources.captions && this._playerConfig.sources.captions.length)
loadOptions.media.tracks = this._playerConfig.sources.captions.map((caption, index) => {
let newTrack;
newTrack = new chrome.cast.media.Track(index + 1, chrome.cast.media.TrackType.TEXT);
Utils.Object.mergeDeep(newTrack, {
trackContentId: caption.url,
name: caption.label,
language: caption.language
});
return newTrack;
if (this._playerConfig.sources.captions && this._playerConfig.sources.captions.length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
But I would export all the external captions handling to a separate method since _getLoadOptions start to become unreadable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const externalTracks = [];
this._playerConfig.sources.captions.forEach((caption, index) => {
if (caption.type === 'vtt' || caption.url.endsWith('.vtt')) {
let newTrack;
newTrack = new chrome.cast.media.Track(index + 1, chrome.cast.media.TrackType.TEXT);
Utils.Object.mergeDeep(newTrack, {
trackContentId: caption.url,
trackContentType: 'text/vtt',
name: caption.label,
language: caption.language
});
externalTracks.push(newTrack);
} else {
this._logger.warn(`Text track type ${caption.type} is unsupported by Cast receiver`);
}
});
externalTracks.length && (loadOptions.media.tracks = externalTracks);
}

return loadOptions;
}
Expand Down