@@ -8,7 +8,7 @@ import { getCachedPlaylistSongs, getCachedPlaylists,
88 getCurrentSongIndex , setCurrentSongIndex , setCurrentSongTime ,
99 getCurrentSongTime } from "./storageService" ;
1010import { shuffleArray } from "./util" ;
11- import { updateMediaSessionMetadata , updateMediaSessionPlaybackState } from "./mediasessionService" ;
11+ import { updateMediaSessionMetadata , updateMediaSessionPlaybackState , updatePositionState } from "./mediasessionService" ;
1212
1313export let currentSong = writable ( { id : - 999 , title : "" , artist : "" , album : "" , source_id : "" } ) ;
1414export let isPlaying = writable ( false ) ;
@@ -52,7 +52,6 @@ export function initializePlaybackService() {
5252 playOrPauseSong ( playlistSongs [ songIndex ] . id ) ;
5353 }
5454
55-
5655 audioElement . addEventListener ( "play" , ( ) => {
5756 isPlaying . set ( true ) ;
5857 updateMediaSessionPlaybackState ( true ) ;
@@ -65,7 +64,7 @@ export function initializePlaybackService() {
6564 updateMediaSessionPlaybackState ( false ) ;
6665 if ( get ( isLoopingEnabled ) ) {
6766 audioElement . currentTime = 0 ;
68- audioElement . play ( ) ;
67+ audioElement . load ( ) ;
6968 } else {
7069 nextSong ( ) ;
7170 }
@@ -90,7 +89,7 @@ export function initializePlaybackService() {
9089 }
9190
9291 setCurrentSongTime ( audioElement . currentTime ) ;
93-
92+ updatePositionState ( audioElement . currentTime , audioElement . duration ) ;
9493 playPercentage . set ( percentage ) ;
9594 } ) ;
9695
@@ -132,6 +131,7 @@ export function playOrPauseSong(songId) {
132131 else if ( get ( isPlaying ) ) {
133132 audioElement . pause ( ) ;
134133 } else {
134+ // data is already loaded, just play
135135 audioElement . play ( ) ;
136136 }
137137}
@@ -174,6 +174,9 @@ export function setPlaylists(playlistId) {
174174 // and update playlistSongs accordingly if shuffle is enabled
175175 return ; // Already set to this playlist
176176 }
177+ isLoopingEnabled . set ( false ) ;
178+ isShuffledEnabled . set ( false ) ;
179+ setPlaybackState ( false , false ) ;
177180 currentPlaylistId = playlistId ;
178181 originalPlaylistSongs = getCachedPlaylistSongs ( playlistId ) ;
179182 playlistSongs = originalPlaylistSongs ;
0 commit comments