Skip to content

Commit

Permalink
Apple auth
Browse files Browse the repository at this point in the history
  • Loading branch information
tteggel committed Dec 26, 2024
1 parent 0c5b2f2 commit 776bfe0
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions ptp.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ <h1>Pass the Parcel - Apple Music</h1>
music = MusicKit.getInstance();

// We want to loop the entire playlist when it ends
//music.player.repeatMode = MusicKit.REPEAT_MODE_ALL;
music.repeatMode = MusicKit.REPEAT_MODE_ALL;

// Let the user sign in to Apple Music
appleSignInBtn.disabled = false;

// Update track info when player changes tracks
//music.player.addEventListener('mediaItemDidChange', updateSongInfo);

// Also handle playback ended (just in case user’s snippet ends exactly at track end)
// music.player.addEventListener('playbackStateDidChange', () => {
// if (music.player.playbackState === MusicKit.PlaybackStates.ENDED) {
// // If a track ended, Apple MusicKit auto-advances to next track in the queue,
// // so we just update our displayed info.
// updateSongInfo();
// }
// });
music.addEventListener('mediaItemDidChange', updateSongInfo);

//Also handle playback ended (just in case user’s snippet ends exactly at track end)
music.addEventListener('playbackStateDidChange', () => {
if (music.playbackState === MusicKit.PlaybackStates.ENDED) {
// If a track ended, Apple MusicKit auto-advances to next track in the queue,
// so we just update our displayed info.
updateSongInfo();
}
});
});

/***********************************************
Expand Down Expand Up @@ -140,7 +140,7 @@ <h1>Pass the Parcel - Apple Music</h1>
const snippetLength = Math.floor(Math.random() * 26) + 5;

// Start or resume playback
music.player.play();
music.play();

// Clear any previous snippet timeout
if (snippetTimeout) {
Expand All @@ -151,7 +151,7 @@ <h1>Pass the Parcel - Apple Music</h1>
snippetTimeout = setTimeout(() => {
// If we’re at or beyond the track’s duration, Apple MusicKit will auto-advance.
// We just pause, letting Apple’s logic handle the next track if the song ended exactly.
music.player.pause();
music.pause();

// Re-enable button
playSnippetBtn.disabled = false;
Expand All @@ -162,7 +162,7 @@ <h1>Pass the Parcel - Apple Music</h1>
* 5) Update Song Info Display
***********************************************/
function updateSongInfo() {
const currentItem = music.player.nowPlayingItem;
const currentItem = music.nowPlayingItem;
if (currentItem) {
// Construct a user-friendly label
const artist = currentItem.artistName || 'Unknown Artist';
Expand Down

0 comments on commit 776bfe0

Please sign in to comment.