Created
April 19, 2021 21:02
-
-
Save seresk/b94e341670bd982db0766d025cb51884 to your computer and use it in GitHub Desktop.
AppleMusicPlayBehavior partial implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class AppleMusicPlayBehavior implements IPlayBehaviour { | |
public TAG: string; | |
public playState: PlayStateEnum; | |
public playedMs: number; | |
public playlist: NowPlayingPlaylistModel = new NowPlayingPlaylistModel(); | |
public progress: number; | |
public trackPlayedLabel: string; | |
public trackRemainingLabel: string; | |
public volume: number; | |
musicKit: MusicKitInstance; | |
constructor(private streamingService: StreamingService, private publisher: PublisherService) { | |
this.musicKit = AppleMusicKit.getInstance(); | |
} | |
seek(seekToMs: number): void { | |
this.isSeeking = true; | |
if (seekToMs < 0) { | |
seekToMs = 0; | |
} | |
if (seekToMs > this.playlist.currentTrack.durationMs) { | |
return; | |
} | |
this.playlist.progressMs = seekToMs; | |
this.playedMs = this.playlist.progressMs; | |
this.progress = Math.min(this.playedMs / Math.floor(this.playlist.currentTrack.durationMs) * 100, 100); | |
const playbackTimeDidChangeModel = new PlaybackTimeDidChangeModel(); | |
playbackTimeDidChangeModel.currentPlaybackDuration = this.playlist.progressMs / 1000; | |
playbackTimeDidChangeModel.currentPlaybackTime = this.playlist.currentTrack.durationMs / 1000; | |
playbackTimeDidChangeModel.currentPlaybackTimeRemaining = (this.playlist.currentTrack.durationMs - this.playlist.progressMs) / 1000; | |
this.setPlaybackLabels(playbackTimeDidChangeModel); | |
this.clearSeekRequestTimeout(); | |
this.setSeekRequestTimeout(seekToMs); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment