MusicKitJS:无法播放用户图书馆中的歌曲 [英] MusicKitJS: Can't play songs from user's library

查看:110
本文介绍了MusicKitJS:无法播放用户图书馆中的歌曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试Apple的 MusicKit JS https://developer.apple.com/documentation/musickitjs )。我在播放从图书馆端点获取的歌曲时遇到了麻烦,而且由于id格式,我可以告诉它。

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.

如果我使用他们的doc示例并将队列设置为ID为 1025210938 的专辑,则歌曲播放正常。但是当从用户的iCloud库中获取歌曲时(例如 / v1 / me / library / albums 或者在musickitjs案例中 music.api.library)。专辑())我得到一个看起来像 l.uUZAkT3 的I​​D,当我尝试播放时,我们没有做任何事情。

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.

也许更熟悉Apple Music的API如何工作或者使用MusicKit for iOS的人可以让我知道为什么会这样或者如何获得一个可用的id用户的库项目。

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.

推荐答案

大多数MusicKit JS都基于Promises。 setQueue method是这些基于Promise的方法之一。

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

特别是 setQueue 可以为您获取数据。

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

为了确保数据可以使用,您可能希望在已解决的Promise中执行任何回放功能。

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();
});

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

这篇关于MusicKitJS:无法播放用户图书馆中的歌曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆