'MusicKitJS: Can't play songs from user's library

So I'm experimenting with Apple's MusicKit JS (https://developer.apple.com/documentation/musickitjs) that was released last week. I'm having trouble playing songs fetched from the library endpoints and from what I can tell it's because of the id format.

If I use their doc examples and set the queue to an album with an id like 1025210938, songs play fine. However when getting a song from a user's iCloud library (ie. /v1/me/library/albums or in musickitjs case music.api.library.albums()) I get an id that looks like l.uUZAkT3 and those do not do anything when I try to play them.

Maybe something who is more familiar with how Apple Music's API works in general or used MusicKit for iOS would be able to let me know why this is or how to get a usable id for a user's library items.



Solution 1:[1]

For @AlexRabin: I did playback when clicking on li element like this:

$('div.results').on("click",'li',function(){
  var index = $(this).index();
  
  console.log("li clicked "+index);
  var klasarodzica = $(this).parent().attr("class");
  let playParams = {};
  if (klasarodzica == "songs") {
     playParams = window.songsarray[index].attributes.playParams;
  }
  if (klasarodzica == "albums") {
     playParams = window.albumsarray[index].attributes.playParams;
  }

  var kind = playParams.kind;
  let id = playParams.id;
  let playobj ={[kind]:id};
  music.setQueue(playobj).then(function() {
    music.play();
  });

});

But as I said you have to write entire app in event listener, otherwise music object is unknown.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sebastian