@@ -145,7 +145,8 @@ export const createQueueMachine = setup({
145145 const nextActor = context . trackActors [ nextIdx ] ;
146146 if ( nextActor ) {
147147 console . log ( `🚀 QUEUE: Activating and playing track ${ nextIdx } ` ) ;
148- // Directly activate and play the next track
148+ // Reset track position to start and then activate and play
149+ nextActor . send ( { type : 'SEEK' , time : 0 } ) ;
149150 nextActor . send ( { type : 'ACTIVATE' } ) ;
150151 nextActor . send ( { type : 'PLAY' } ) ;
151152 }
@@ -256,11 +257,18 @@ export const createQueueMachine = setup({
256257 currentTrackIdx : 0 ,
257258 } ) ,
258259 setVolume : assign ( {
259- volume : ( { event } ) => {
260- if ( event . type === 'SET_VOLUME' ) {
261- return Math . max ( 0 , Math . min ( 1 , event . volume ) ) ;
262- }
263- return 1 ;
260+ volume : ( { context, event } ) => {
261+ if ( event . type !== 'SET_VOLUME' ) return context . volume ;
262+
263+ const newVolume = Math . max ( 0 , Math . min ( 1 , event . volume ) ) ;
264+ console . log ( `🔊 QUEUE: Setting volume to ${ ( newVolume * 100 ) . toFixed ( 0 ) } %` ) ;
265+
266+ // Send volume update to all track actors
267+ context . trackActors . forEach ( ( trackActor ) => {
268+ trackActor . send ( { type : 'SET_VOLUME' , volume : newVolume } ) ;
269+ } ) ;
270+
271+ return newVolume ;
264272 } ,
265273 } ) ,
266274 spawnInitialTracks : assign ( {
@@ -459,36 +467,42 @@ export const createQueueMachine = setup({
459467 if ( typeof window !== 'undefined' && 'mediaSession' in navigator ) {
460468 const currentTrackMeta = context . trackMetadata ?. [ context . currentTrackIdx ] ;
461469 const defaultTitle = `Track ${ context . currentTrackIdx + 1 } ` ;
462-
470+
463471 navigator . mediaSession . metadata = new MediaMetadata ( {
464472 title : currentTrackMeta ?. title || defaultTitle ,
465473 artist : currentTrackMeta ?. artist || 'Unknown Artist' ,
466474 album : currentTrackMeta ?. album || 'Gapless Playlist' ,
467- artwork : currentTrackMeta ?. artwork ? [
468- { src : currentTrackMeta . artwork , sizes : '96x96' , type : 'image/png' } ,
469- { src : currentTrackMeta . artwork , sizes : '128x128' , type : 'image/png' } ,
470- { src : currentTrackMeta . artwork , sizes : '192x192' , type : 'image/png' } ,
471- { src : currentTrackMeta . artwork , sizes : '256x256' , type : 'image/png' } ,
472- { src : currentTrackMeta . artwork , sizes : '384x384' , type : 'image/png' } ,
473- { src : currentTrackMeta . artwork , sizes : '512x512' , type : 'image/png' } ,
474- ] : [ ]
475+ artwork : currentTrackMeta ?. artwork
476+ ? [
477+ { src : currentTrackMeta . artwork , sizes : '96x96' , type : 'image/png' } ,
478+ { src : currentTrackMeta . artwork , sizes : '128x128' , type : 'image/png' } ,
479+ { src : currentTrackMeta . artwork , sizes : '192x192' , type : 'image/png' } ,
480+ { src : currentTrackMeta . artwork , sizes : '256x256' , type : 'image/png' } ,
481+ { src : currentTrackMeta . artwork , sizes : '384x384' , type : 'image/png' } ,
482+ { src : currentTrackMeta . artwork , sizes : '512x512' , type : 'image/png' } ,
483+ ]
484+ : [ ] ,
475485 } ) ;
476486
477487 console . log ( '📱 DEVICE: Updated MediaSession metadata' , {
478488 title : currentTrackMeta ?. title || defaultTitle ,
479- artist : currentTrackMeta ?. artist || 'Unknown Artist'
489+ artist : currentTrackMeta ?. artist || 'Unknown Artist' ,
480490 } ) ;
481491 }
482492 } ,
483493
484494 updateMediaSessionPlaybackState : ( { context } ) => {
485495 if ( typeof window !== 'undefined' && 'mediaSession' in navigator ) {
486496 // Get current state from context or derive it
487- const isPlaying = context . trackActors . some ( actor => {
497+ const isPlaying = context . trackActors . some ( ( actor ) => {
488498 const snapshot = actor . getSnapshot ( ) ;
489- return snapshot . status === 'active' && snapshot . matches && snapshot . matches ( { playback : 'playing' } ) ;
499+ return (
500+ snapshot . status === 'active' &&
501+ snapshot . matches &&
502+ snapshot . matches ( { playback : 'playing' } )
503+ ) ;
490504 } ) ;
491-
505+
492506 navigator . mediaSession . playbackState = isPlaying ? 'playing' : 'paused' ;
493507 console . log ( '📱 DEVICE: Updated playback state to' , navigator . mediaSession . playbackState ) ;
494508 }
@@ -502,7 +516,12 @@ export const createQueueMachine = setup({
502516} ) . createMachine ( {
503517 id : 'queue' ,
504518 initial : 'paused' ,
505- entry : [ 'spawnInitialTracks' , 'loadCurrentTrack' , 'setupMediaSession' , 'updateMediaSessionMetadata' ] ,
519+ entry : [
520+ 'spawnInitialTracks' ,
521+ 'loadCurrentTrack' ,
522+ 'setupMediaSession' ,
523+ 'updateMediaSessionMetadata' ,
524+ ] ,
506525 context : ( { input } ) => ( {
507526 tracks : input ?. tracks || [ ] ,
508527 currentTrackIdx : 0 ,
0 commit comments