diff --git a/src/WebOsVideo/WebOsVideo.js b/src/WebOsVideo/WebOsVideo.js index 420fecb..4b9e2df 100644 --- a/src/WebOsVideo/WebOsVideo.js +++ b/src/WebOsVideo/WebOsVideo.js @@ -449,9 +449,9 @@ function WebOsVideo(options) { var nrAudio = 0; textTracks = []; audioTracks = []; - var respArr = resp || []; - respArr.forEach(function(track) { - if (track.type === 'text') { + tracksData = resp; + if (((tracksData || {}).subs || []).length) { + tracksData.subs.forEach(function(track) { var textTrackId = nrSubs; nrSubs++; if (!currentSubTrack && !textTracks.length) { @@ -465,7 +465,12 @@ function WebOsVideo(options) { embedded: true, mode: textTrackId === currentSubTrack ? 'showing' : 'disabled', }); - } else if (track.type === 'audio') { + }); + onPropChanged('subtitlesTracks'); + onPropChanged('selectedSubtitlesTrackId'); + } + if (((tracksData || {}).audio || []).length) { + tracksData.audio.forEach(function(track) { var audioTrackId = nrAudio; nrAudio++; if (!currentAudioTrack && !audioTracks.length) { @@ -479,13 +484,7 @@ function WebOsVideo(options) { embedded: true, mode: audioTrackId === currentAudioTrack ? 'showing' : 'disabled', }); - } - }) - if (((tracksData || {}).subs || []).length) { - onPropChanged('subtitlesTracks'); - onPropChanged('selectedSubtitlesTrackId'); - } - if (((tracksData || {}).audio || []).length) { + }); onPropChanged('audioTracks'); onPropChanged('selectedAudioTrackId'); } diff --git a/src/tracksData.js b/src/tracksData.js index ea4356e..88388bc 100644 --- a/src/tracksData.js +++ b/src/tracksData.js @@ -1,8 +1,8 @@ module.exports = function(url, cb) { fetch('http://127.0.0.1:11470/tracks/'+encodeURIComponent(url)).then(function(resp) { resp.json().then(function(tracks) { - var audioTracks = tracks.filter(function(el) { return el['@type'] === 'Audio'; }); - var subsTracks = tracks.filter(function(el) { return el['@type'] === 'Text'; }); + var audioTracks = tracks.filter(function(el) { return el.type === 'audio'; }); + var subsTracks = tracks.filter(function(el) { return el.type === 'text'; }); cb({ audio: audioTracks, subs: subsTracks }); }).catch(function(err) { // eslint-disable-next-line no-console