From 9dc0f28800fd17eef442f868bd12c3017400a992 Mon Sep 17 00:00:00 2001 From: Albin Larsson Date: Fri, 8 Jun 2018 21:16:17 +0200 Subject: [PATCH] Avoid condition in getTracks --- src/js/captions.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/js/captions.js b/src/js/captions.js index b3723885..38167d7a 100644 --- a/src/js/captions.js +++ b/src/js/captions.js @@ -127,13 +127,10 @@ const captions = { // Get the tracks getTracks() { - // Return empty array at least - if (utils.is.nullOrUndefined(this.media)) { - return []; - } - - // Only get accepted kinds - return Array.from(this.media.textTracks || []).filter(track => [ + // Handle media or textTracks missing or null + const { textTracks } = this.media || {}; + // Filter out invalid tracks kinds (like metadata) + return Array.from(textTracks || []).filter(track => [ 'captions', 'subtitles', ].includes(track.kind));