Skip to content

Commit

Permalink
Merge pull request jellyfin#4891 from Sky-High/playback-fixes-for-chr…
Browse files Browse the repository at this point in the history
…omecast

Fix playback control issues with chromecast
  • Loading branch information
thornbill authored Nov 8, 2023
2 parents bd54821 + e51ab7a commit 3421261
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 68 deletions.
18 changes: 11 additions & 7 deletions src/components/nowPlayingBar/nowPlayingBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,20 @@ function bindEvents(elem) {

elem.querySelector('.previousTrackButton').addEventListener('click', function (e) {
if (currentPlayer) {
if (lastPlayerState.NowPlayingItem.MediaType === 'Audio') {
if (playbackManager.isPlayingAudio(currentPlayer)) {
// Cancel this event if doubleclick is fired. The actual previousTrack will be processed by the 'dblclick' event
if (e.detail > 1 ) {
return;
}

// Return to start of track, unless we are already (almost) at the beginning. In the latter case, continue and move
// to the previous track, unless we are at the first track so no previous track exists.
if (currentPlayer._currentTime >= 5 || playbackManager.getCurrentPlaylistIndex(currentPlayer) <= 1) {
// currentTime is in msec.

if (playbackManager.currentTime(currentPlayer) >= 5 || playbackManager.getCurrentPlaylistIndex(currentPlayer) <= 1) {
playbackManager.seekPercent(0, currentPlayer);
// This is done automatically by playbackManager, however, setting this here gives instant visual feedback.
// TODO: Check why seekPercentage doesn't reflect the changes inmmediately, so we can remove this workaround.
// TODO: Check why seekPercent doesn't reflect the changes inmmediately, so we can remove this workaround.
positionSlider.value = 0;
return;
}
Expand Down Expand Up @@ -574,7 +577,8 @@ function updateNowPlayingInfo(state) {
itemContextMenu.show(Object.assign({
item: item,
user: user
}, options));
}, options))
.catch(() => { /* no-op */ });
});
});
}
Expand Down Expand Up @@ -642,7 +646,8 @@ function hideNowPlayingBar() {
}

function onPlaybackStopped(e, state) {
console.debug('nowplaying event: ' + e.type);
console.debug('[nowPlayingBar:onPlaybackStopped] event: ' + e.type);

const player = this;

if (player.isLocalPlayer) {
Expand All @@ -669,7 +674,7 @@ function onStateChanged(event, state) {
return;
}

console.debug('nowplaying event: ' + event.type);
console.debug('[nowPlayingBar:onStateChanged] event: ' + event.type);
const player = this;

if (!state.NowPlayingItem || layoutManager.tv || state.IsFullscreen === false) {
Expand Down Expand Up @@ -792,4 +797,3 @@ document.addEventListener('viewbeforeshow', function (e) {
}
}
});

12 changes: 8 additions & 4 deletions src/components/remotecontrol/remotecontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ function updateNowPlayingInfo(context, state, serverId) {
itemContextMenu.show(Object.assign({
item: fullItem,
user: user
}, options));
}, options))
.catch(() => { /* no-op */ });
});
});
});
Expand Down Expand Up @@ -773,17 +774,20 @@ export default function () {

context.querySelector('.btnPreviousTrack').addEventListener('click', function (e) {
if (currentPlayer) {
if (lastPlayerState.NowPlayingItem.MediaType === 'Audio') {
if (playbackManager.isPlayingAudio(currentPlayer)) {
// Cancel this event if doubleclick is fired. The actual previousTrack will be processed by the 'dblclick' event
if (e.detail > 1 ) {
return;
}

// Return to start of track, unless we are already (almost) at the beginning. In the latter case, continue and move
// to the previous track, unless we are at the first track so no previous track exists.
if (currentPlayer._currentTime >= 5 || playbackManager.getCurrentPlaylistIndex(currentPlayer) <= 1) {
// currentTime is in msec.

if (playbackManager.currentTime(currentPlayer) >= 5 || playbackManager.getCurrentPlaylistIndex(currentPlayer) <= 1) {
playbackManager.seekPercent(0, currentPlayer);
// This is done automatically by playbackManager, however, setting this here gives instant visual feedback.
// TODO: Check why seekPercentage doesn't reflect the changes inmmediately, so we can remove this workaround.
// TODO: Check why seekPercent doesn't reflect the changes inmmediately, so we can remove this workaround.
positionSlider.value = 0;
return;
}
Expand Down
17 changes: 9 additions & 8 deletions src/components/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,15 @@ function showContextMenu(card, options) {
playlistId: playlistId,
collectionId: collectionId,
user: user

}, options || {})).then(result => {
if (result.command === 'playallfromhere' || result.command === 'queueallfromhere') {
executeAction(card, options.positionTo, result.command);
} else if (result.updated || result.deleted) {
notifyRefreshNeeded(card, options.itemsContainer);
}
});
}, options || {}))
.then(result => {
if (result.command === 'playallfromhere' || result.command === 'queueallfromhere') {
executeAction(card, options.positionTo, result.command);
} else if (result.updated || result.deleted) {
notifyRefreshNeeded(card, options.itemsContainer);
}
})
.catch(() => { /* no-op */ });
});
});
});
Expand Down
16 changes: 9 additions & 7 deletions src/controllers/itemDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1966,13 +1966,15 @@ export default function (view, params) {
selectedItem = item;

apiClient.getCurrentUser().then(function (user) {
itemContextMenu.show(getContextMenuOptions(selectedItem, user, button)).then(function (result) {
if (result.deleted) {
appRouter.goHome();
} else if (result.updated) {
reload(self, view, params);
}
});
itemContextMenu.show(getContextMenuOptions(selectedItem, user, button))
.then(function (result) {
if (result.deleted) {
appRouter.goHome();
} else if (result.updated) {
reload(self, view, params);
}
})
.catch(() => { /* no-op */ });
});
});
}
Expand Down
Loading

0 comments on commit 3421261

Please sign in to comment.