mirror of
https://github.com/jeffvli/feishin.git
synced 2026-07-22 02:16:39 +02:00
fix mediasession handlers breaking after player stop event
This commit is contained in:
@@ -1055,6 +1055,8 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
? state.queue.shuffled.length
|
? state.queue.shuffled.length
|
||||||
: queue.items.length;
|
: queue.items.length;
|
||||||
|
|
||||||
|
const isStopped = state.player.status === PlayerStatus.STOPPED;
|
||||||
|
|
||||||
if (repeat === PlayerRepeat.ONE) {
|
if (repeat === PlayerRepeat.ONE) {
|
||||||
// Manual next while repeat-one is active should still advance in the queue.
|
// Manual next while repeat-one is active should still advance in the queue.
|
||||||
const nextIndex = Math.min(playbackLength - 1, currentIndex + 1);
|
const nextIndex = Math.min(playbackLength - 1, currentIndex + 1);
|
||||||
@@ -1063,6 +1065,10 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
state.player.index = nextIndex;
|
state.player.index = nextIndex;
|
||||||
state.player.playerNum = 1;
|
state.player.playerNum = 1;
|
||||||
setTimestampStore(0);
|
setTimestampStore(0);
|
||||||
|
|
||||||
|
if (isStopped) {
|
||||||
|
state.player.status = PlayerStatus.PLAYING;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
eventEmitter.emit('MEDIA_NEXT', {
|
eventEmitter.emit('MEDIA_NEXT', {
|
||||||
@@ -1112,6 +1118,10 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
state.player.index = nextIndex;
|
state.player.index = nextIndex;
|
||||||
state.player.playerNum = 1;
|
state.player.playerNum = 1;
|
||||||
setTimestampStore(0);
|
setTimestampStore(0);
|
||||||
|
|
||||||
|
if (isStopped) {
|
||||||
|
state.player.status = PlayerStatus.PLAYING;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
eventEmitter.emit('MEDIA_NEXT', {
|
eventEmitter.emit('MEDIA_NEXT', {
|
||||||
@@ -1246,10 +1256,17 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
previousIndex = Math.max(0, currentIndex - 1);
|
previousIndex = Math.max(0, currentIndex - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Same Chromium Media Session pitfall as mediaNext: a STOPPED→new-src
|
||||||
|
// transition without PLAYING drops OS media-key routing.
|
||||||
|
const resumeFromStopped = get().player.status === PlayerStatus.STOPPED;
|
||||||
|
|
||||||
set((state) => {
|
set((state) => {
|
||||||
state.player.index = previousIndex;
|
state.player.index = previousIndex;
|
||||||
state.player.playerNum = 1;
|
state.player.playerNum = 1;
|
||||||
setTimestampStore(0);
|
setTimestampStore(0);
|
||||||
|
if (resumeFromStopped) {
|
||||||
|
state.player.status = PlayerStatus.PLAYING;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
eventEmitter.emit('MEDIA_PREV', {
|
eventEmitter.emit('MEDIA_PREV', {
|
||||||
|
|||||||
Reference in New Issue
Block a user