Skip to content

Commit

Permalink
Stop relying on mediaSource.MediaStreams[index].Index == index.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwalton3 committed Jun 26, 2022
1 parent 9baa52e commit 01ef2f2
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions native/mpvVideoPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,27 @@
return null;
}

/**
* @private
*/
getStreamByIndex(mediaStreams, jellyIndex) {
for (const source of mediaStreams) {
if (source.Index == jellyIndex) {
return source;
}
}

return null;
}

/**
* @private
*/
getSubtitleParam() {
const options = this._currentPlayOptions;

if (this._subtitleTrackIndexToSetOnPlaying != null && this._subtitleTrackIndexToSetOnPlaying >= 0) {
const initialSubtitleStream = options.mediaSource.MediaStreams[this._subtitleTrackIndexToSetOnPlaying];
const initialSubtitleStream = this.getStreamByIndex(options.mediaSource.MediaStreams, this._subtitleTrackIndexToSetOnPlaying);
if (!initialSubtitleStream || initialSubtitleStream.DeliveryMethod === 'Encode') {
this._subtitleTrackIndexToSetOnPlaying = -1;
} else if (initialSubtitleStream.DeliveryMethod === 'External') {
Expand Down Expand Up @@ -300,7 +313,7 @@
const options = this._currentPlayOptions;

if (this._audioTrackIndexToSetOnPlaying != null && this._audioTrackIndexToSetOnPlaying >= 0) {
const initialAudioStream = options.mediaSource.MediaStreams[this._audioTrackIndexToSetOnPlaying];
const initialAudioStream = this.getStreamByIndex(options.mediaSource.MediaStreams, this._audioTrackIndexToSetOnPlaying);
if (!initialAudioStream) {
return '#1';
}
Expand Down

0 comments on commit 01ef2f2

Please sign in to comment.