From a50fae3b7d264d5774444829169b1676cfdb74e6 Mon Sep 17 00:00:00 2001 From: Ivan Schurawel Date: Thu, 17 Nov 2022 17:21:12 -0500 Subject: [PATCH] chore: simplify/refactor to reuse existing method --- src/components/playback/playbackmanager.js | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/components/playback/playbackmanager.js b/src/components/playback/playbackmanager.js index 493df16e1..f19d1f0fa 100644 --- a/src/components/playback/playbackmanager.js +++ b/src/components/playback/playbackmanager.js @@ -900,26 +900,12 @@ class PlaybackManager { return streams.filter((stream) => self.trackHasSecondarySubtitleSupport(stream, player)); }; - function getCurrentSubtitleStream(player) { + function getCurrentSubtitleStream(player, isSecondaryStream = false) { if (!player) { throw new Error('player cannot be null'); } - const index = getPlayerData(player).subtitleStreamIndex; - - if (index == null || index === -1) { - return null; - } - - return self.getSubtitleStream(player, index); - } - - function getCurrentSecondarySubtitleStream(player) { - if (!player) { - throw new Error('player cannot be null'); - } - - const index = getPlayerData(player).secondarySubtitleStreamIndex; + const index = isSecondaryStream ? getPlayerData(player).secondarySubtitleStreamIndex : getPlayerData(player).subtitleStreamIndex; if (index == null || index === -1) { return null; @@ -1598,7 +1584,7 @@ class PlaybackManager { } } - const currentStream = getCurrentSecondarySubtitleStream(player); + const currentStream = getCurrentSubtitleStream(player, true); const newStream = self.getSubtitleStream(player, index);