Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions src/components/playback/playbackmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3130,6 +3130,31 @@
};
}

// Find the id of the version (media source) of an item whose name matches the
// currently playing version, so auto-advancing keeps the same version across episodes.
function getMatchingMediaSourceId(apiClient, item, versionName) {

Check warning on line 3135 in src/components/playback/playbackmanager.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Move function 'getMatchingMediaSourceId' to the outer scope.

See more on https://sonarcloud.io/project/issues?id=jellyfin_jellyfin-web&issues=AZ6HfcTpmq3pUyCTDAv0&open=AZ6HfcTpmq3pUyCTDAv0&pullRequest=7984
if (!versionName) {
Comment thread
Shadowghost marked this conversation as resolved.
Outdated
return Promise.resolve(null);
}

const findMatch = function (mediaSources) {
if (!mediaSources || mediaSources.length < 2) {
return null;
}
const match = mediaSources.find(source => source.Name === versionName);
return match ? match.Id : null;
};

// Queue items usually only carry their primary media source, so the merged alternate versions are missing.
if (item.MediaSources?.length > 1) {
return Promise.resolve(findMatch(item.MediaSources));
}

return apiClient.getItem(apiClient.getCurrentUserId(), item.Id)
Comment thread
Shadowghost marked this conversation as resolved.
.then(fullItem => findMatch(fullItem.MediaSources))
.catch(() => null);
}

self.nextTrack = function (player) {
Comment thread
Shadowghost marked this conversation as resolved.
player = player || self._currentPlayer;
if (player && !enableLocalPlaylistManagement(player)) {
Expand All @@ -3141,11 +3166,19 @@
if (newItemInfo) {
console.debug('playing next track');

const prevSource = getPreviousSource(player);
const newItemPlayOptions = newItemInfo.item.playOptions || getDefaultPlayOptions();
const apiClient = ServerConnections.getApiClient(newItemInfo.item.ServerId);

playInternal(newItemInfo.item, newItemPlayOptions, function () {
setPlaylistState(newItemInfo.item.PlaylistItemId, newItemInfo.index);
}, getPreviousSource(player));
getMatchingMediaSourceId(apiClient, newItemInfo.item, prevSource.Name).then(function (mediaSourceId) {
if (mediaSourceId) {
newItemPlayOptions.mediaSourceId = mediaSourceId;
}

playInternal(newItemInfo.item, newItemPlayOptions, function () {
setPlaylistState(newItemInfo.item.PlaylistItemId, newItemInfo.index);
}, prevSource);
});
}
};

Expand Down
Loading