Browse Source

Stop relying on mediaSource.MediaStreams[index].Index == index.

Ian Walton 2 years ago
parent
commit
01ef2f2ffc
1 changed files with 15 additions and 2 deletions
  1. 15 2
      native/mpvVideoPlayer.js

+ 15 - 2
native/mpvVideoPlayer.js

@@ -263,6 +263,19 @@
             return null;
         }
 
+        /**
+         * @private
+         */
+        getStreamByIndex(mediaStreams, jellyIndex) {
+            for (const source of mediaStreams) {
+                if (source.Index == jellyIndex) {
+                    return source;
+                }
+            }
+
+            return null;
+        }
+
         /**
          * @private
          */
@@ -270,7 +283,7 @@
             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') {
@@ -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';
                 }