如何使用 Spotify Apps API 对象?

发布于 2024-12-19 11:14:43 字数 462 浏览 0 评论 0原文

新的 Spotify Apps Javascript API 包含许多对象,例如专辑、库、链接等。但是您如何在应用程序中实际实例化和使用它们中的任何一个呢? 我已经查看了教程应用程序,但其中使用的所有内容都是 trackPlayer 对象,据我所知,该对象尚未记录。 这个问题的答案建议查看 Spotify 的应用程序包中的内容。应用程序/内容/资源/cef_views。但是,我在 Mac 上似乎找不到这个文件夹,在 Windows 上似乎也没有相应的文件夹。

任何帮助将不胜感激。

The new Spotify Apps Javascript API contains a number of objects like Album, Library, Link etc. But how do you actually instantiate and use any of them in your app?
I've looked at the tutorial app but all that is used there is the trackPlayer object which isn't documented as far as I can tell.
The answer to this question suggests looking in the in the app bundle at Spotify.app/Contents/Resources/cef_views. However, I can't seem to find this on my Mac and there seems to be no corresponding folder on Windows.

Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅哥哥的热头脑 2024-12-26 11:14:43

首先,回答关于在哪里找到该文件夹​​的第二个问题(我也在我自己的原始帖子中将其作为评论发布):


在 Windows 中,该文件夹位于 .zip 文件 (resources.zip )在数据文件夹中,然后是 Spotify.exe。就我而言,这是

C:\Users\buchetics\AppData\Roaming\Spotify\Data\resources.zip

在 Mac 上,您需要右键单击 Spotify.app 并选择 Show Package Content (或类似的内容),然后您可以导航到捆绑包内的文件夹。


好的,现在回答你原来的问题。您可以像这样获取 API 对象:

window.Models = sp.require("sp://import/scripts/api/models");
window.Views = sp.require("sp://import/scripts/api/views");

然后,您可以使用 中描述的所有方法和属性API参考(仍然不是很好)。
例如:

window.CurrentPlaylist = new Models.Playlist();
var track = Models.Track.fromURI("spotify:track:4n6AGL10M8fbm8oHxhK16j");
CurrentPlaylist.add(track);

等等。 Models API 非常易于使用,Views 对象可用于呈现类似于常规 Spotify 列表的曲目列表。对于其他 API 调用,例如获取当前播放曲目,您需要使用 var sp = getSpotifyApi(1); 返回的核心 API。但是,目前还没有这方面的文档,最好的建议是查看在 cef_views 中找到的代码,或者使用可用应用程序上的检查器来查找有用的代码片段(并非所有应用程序都公开其以易于查看的方式编写代码,但有些代码确实如此,例如“We are Hunted”或“Songkicks”应用程序)。

First, to answer your second question about where to find the folder (I also posted this as a comment in my own original post):


In Windows the folder is located as a .zip file (resources.zip) in the data folder next so Spotify.exe. In my case this is

C:\Users\buchetics\AppData\Roaming\Spotify\Data\resources.zip

On the Mac, you need to right click Spotify.app and select Show Package Content (or something like that), then you can navigate to the folder inside the bundle.


Ok, now to your original question. You can get the API objects like this:

window.Models = sp.require("sp://import/scripts/api/models");
window.Views = sp.require("sp://import/scripts/api/views");

Then, you can use all the methods and properties as described in the API reference (which is still not very good).
For example:

window.CurrentPlaylist = new Models.Playlist();
var track = Models.Track.fromURI("spotify:track:4n6AGL10M8fbm8oHxhK16j");
CurrentPlaylist.add(track);

And so on. The Models API is quite easy to use and the Views object can be used to render a track list similar to the regular Spotify lists. For other API calls, such as getting the current playing track, you need to use the core API which is returend by var sp = getSpotifyApi(1);. However, there is no documentation for this yet and the best advice is to look at the code found in cef_views or use the Inspector on the available apps to find useful code pieces (not all of the apps expose their code in a way to easily look at it, but some do, such as the "We are Hunted" or "Songkicks" app).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文