Skip to content

Commit 56e769d

Browse files
Shadowghostclaude
andcommitted
Apply version matching to previousTrack and skip lookup for single-version items
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9ee65f6 commit 56e769d

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

src/components/playback/playbackmanager.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,8 @@ export class PlaybackManager {
17421742

17431743
getPlaybackInfo(player, apiClient, currentItem, deviceProfile, currentMediaSource.Id, liveStreamId, options).then(function (result) {
17441744
if (validatePlaybackInfoResult(self, result)) {
1745+
// Changing streams requests only the active source; keep the version availability flag.
1746+
result.MediaSources[0].hasAlternateVersions = currentMediaSource.hasAlternateVersions;
17451747
currentMediaSource = result.MediaSources[0];
17461748

17471749
const streamInfo = createStreamInfo(apiClient, currentItem.MediaType, currentItem, currentMediaSource, ticks, player);
@@ -2956,6 +2958,11 @@ export class PlaybackManager {
29562958
if (validatePlaybackInfoResult(self, playbackInfoResult)) {
29572959
return getOptimalMediaSource(apiClient, item, playbackInfoResult.MediaSources).then(function (mediaSource) {
29582960
if (mediaSource) {
2961+
// Remember whether alternate versions were available, so track
2962+
// navigation knows when a version selection needs to be carried over
2963+
// without re-fetching the item.
2964+
mediaSource.hasAlternateVersions = playbackInfoResult.MediaSources.length > 1;
2965+
29592966
if (mediaSource.RequiresOpening && !mediaSource.LiveStreamId) {
29602967
options.audioStreamIndex = null;
29612968
options.subtitleStreamIndex = null;
@@ -3131,9 +3138,14 @@ export class PlaybackManager {
31313138
}
31323139

31333140
// Find the id of the version (media source) of an item whose name matches the
3134-
// currently playing version, so auto-advancing keeps the same version across episodes.
3135-
function getMatchingMediaSourceId(apiClient, item, versionName) {
3136-
if (!versionName) {
3141+
// currently playing version, so track navigation keeps the same version across episodes.
3142+
function getMatchingMediaSourceId(apiClient, item, prevSource) {
3143+
const versionName = prevSource?.Name;
3144+
3145+
// Without alternate versions on the previous item there is no version selection to
3146+
// carry over, so the (potentially remote) lookup is skipped in the common
3147+
// single-version case.
3148+
if (!versionName || !prevSource.hasAlternateVersions) {
31373149
return Promise.resolve(null);
31383150
}
31393151

@@ -3170,7 +3182,7 @@ export class PlaybackManager {
31703182
const newItemPlayOptions = newItemInfo.item.playOptions || getDefaultPlayOptions();
31713183
const apiClient = ServerConnections.getApiClient(newItemInfo.item.ServerId);
31723184

3173-
getMatchingMediaSourceId(apiClient, newItemInfo.item, prevSource.Name).then(function (mediaSourceId) {
3185+
getMatchingMediaSourceId(apiClient, newItemInfo.item, prevSource).then(function (mediaSourceId) {
31743186
if (mediaSourceId) {
31753187
newItemPlayOptions.mediaSourceId = mediaSourceId;
31763188
}
@@ -3194,12 +3206,20 @@ export class PlaybackManager {
31943206
const newItem = playlist[newIndex];
31953207

31963208
if (newItem) {
3209+
const prevSource = getPreviousSource(player);
31973210
const newItemPlayOptions = newItem.playOptions || getDefaultPlayOptions();
31983211
newItemPlayOptions.startPositionTicks = 0;
3212+
const apiClient = ServerConnections.getApiClient(newItem.ServerId);
3213+
3214+
getMatchingMediaSourceId(apiClient, newItem, prevSource).then(function (mediaSourceId) {
3215+
if (mediaSourceId) {
3216+
newItemPlayOptions.mediaSourceId = mediaSourceId;
3217+
}
31993218

3200-
playInternal(newItem, newItemPlayOptions, function () {
3201-
setPlaylistState(newItem.PlaylistItemId, newIndex);
3202-
}, getPreviousSource(player));
3219+
playInternal(newItem, newItemPlayOptions, function () {
3220+
setPlaylistState(newItem.PlaylistItemId, newIndex);
3221+
}, prevSource);
3222+
});
32033223
}
32043224
}
32053225
};

0 commit comments

Comments
 (0)