SpotifyTrack.from constructor

SpotifyTrack.from(
  1. PlaybackState playbackState
)

Implementation

factory SpotifyTrack.from(PlaybackState playbackState) {
  return SpotifyTrack(
    id: playbackState.item!.id,
    title: playbackState.item!.name,
    album: playbackState.item!.album?.name,
    artist: playbackState.item!.artists?.first.name,
    image: playbackState.item!.album?.images?.first.url,
    duration: playbackState.item!.duration ?? Duration.zero,
    position: Duration(milliseconds: playbackState.progressMs ?? 0),
    state: switch (playbackState.isPlaying) {
      true => NowPlayingState.playing,
      false => NowPlayingState.paused,
      null => NowPlayingState.stopped,
    },
    source: "Spotify",
  );
}