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

非 Y 不嫁゛ 提交于 2020-01-03 06:06:11

问题


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.


回答1:


Most of MusicKit JS is based on Promises. The setQueue method is one of these Promise based methods.

In particular setQueue can fetch the data for you, if you do not already have an API data response handy.

In order to ensure the data is ready to be used, you would want to execute any playback functionality in the resolved Promise.

MusicKit.getInstance().setQueue({ album: 'l.abc123'}).then(function(queue) {
    MusicKit.getInstance().play();
});

or

MusicKit.getInstance().api.library.albums().then(function(albums) {
    MusicKit.getInstance().setQueue(albums[0]).then(function(queue) {
        MusicKit.getInstance().play();
    });
});


来源:https://stackoverflow.com/questions/50786400/musickitjs-cant-play-songs-from-users-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!