Ver código fonte

Use relative subtitle/audio indexes. (#271)

Ian Walton 2 anos atrás
pai
commit
b670715a5c
2 arquivos alterados com 72 adições e 16 exclusões
  1. 59 4
      native/mpvVideoPlayer.js
  2. 13 12
      src/player/PlayerComponent.cpp

+ 59 - 4
native/mpvVideoPlayer.js

@@ -243,6 +243,26 @@
             return this.appSettings.get('volume') || 1;
         }
 
+        /**
+         * @private
+         */
+        getRelativeIndexByType(mediaStreams, jellyIndex, streamType) {
+            let relIndex = 1;
+            for (const source of mediaStreams) {
+                if (source.Type != streamType || source.IsExternal) {
+                    continue;
+                }
+
+                if (source.Index == jellyIndex) {
+                    return relIndex;
+                }
+
+                relIndex += 1;
+            }
+
+            return null;
+        }
+
         /**
          * @private
          */
@@ -262,7 +282,43 @@
                 return '';
             }
 
-            return '#' + this._subtitleTrackIndexToSetOnPlaying;
+            const subtitleRelIndex = this.getRelativeIndexByType(
+                options.mediaSource.MediaStreams,
+                this._subtitleTrackIndexToSetOnPlaying,
+                'Subtitle'
+            );
+
+            return subtitleRelIndex != null
+                ? '#' + subtitleRelIndex
+                : '';
+        }
+
+        /**
+         * @private
+         */
+        getAudioParam() {
+            const options = this._currentPlayOptions;
+
+            if (this._audioTrackIndexToSetOnPlaying != null && this._audioTrackIndexToSetOnPlaying >= 0) {
+                const initialAudioStream = options.mediaSource.MediaStreams[this._audioTrackIndexToSetOnPlaying];
+                if (!initialAudioStream) {
+                    return '#1';
+                }
+            }
+
+            if (this._audioTrackIndexToSetOnPlaying == -1 || this._audioTrackIndexToSetOnPlaying == null) {
+                return '#1';
+            }
+
+            const audioRelIndex = this.getRelativeIndexByType(
+                options.mediaSource.MediaStreams,
+                this._audioTrackIndexToSetOnPlaying,
+                'Audio'
+            );
+
+            return audioRelIndex != null
+                ? '#' + audioRelIndex
+                : '#1';
         }
 
         tryGetFramerate(options) {
@@ -300,8 +356,7 @@
                 player.load(val,
                     { startMilliseconds: ms, autoplay: true },
                     streamdata,
-                    (this._audioTrackIndexToSetOnPlaying != null)
-                     ? '#' + this._audioTrackIndexToSetOnPlaying : '#1',
+                    this.getAudioParam(),
                     this.getSubtitleParam(),
                     resolve);
             });
@@ -367,7 +422,7 @@
                 return;
             }
 
-            window.api.player.setAudioStream(index != -1 ? '#' + index : '');
+            window.api.player.setAudioStream(this.getAudioParam());
         }
 
         onEndedInternal() {

+ 13 - 12
src/player/PlayerComponent.cpp

@@ -876,20 +876,21 @@ void PlayerComponent::reselectStream(const QString &streamSelection, MediaType t
 
   QString selection = "no";
 
-  for (auto stream : findStreamsForURL(streamName))
+  if (!streamID.isEmpty())
   {
-    auto map = stream.toMap();
-
-    if (map["type"].toString() != mpvStreamTypeName)
-      continue;
-
-    if (!streamID.isEmpty() && map["ff-index"].toString() == streamID)
+    selection = streamID;
+  } else {
+    for (auto stream : findStreamsForURL(streamName))
     {
-      selection = map["id"].toString();
-      break;
-    } else if (streamID.isEmpty() && map["external-filename"].toString() == streamName) {
-      selection = map["id"].toString();
-      break;
+      auto map = stream.toMap();
+
+      if (map["type"].toString() != mpvStreamTypeName)
+      {
+        continue;
+      } else if (map["external-filename"].toString() == streamName) {
+        selection = map["id"].toString();
+        break;
+      }
     }
   }