【发布时间】:2019-07-05 13:13:11
【问题描述】:
我正在开发一个使用Spotify API 的应用程序。它必须开始一个特定的轨道。我可以做到这一点。
但是在曲目完成后播放停止。我希望 Spotify 播放专辑的以下曲目。有没有办法这样做?
【问题讨论】:
我正在开发一个使用Spotify API 的应用程序。它必须开始一个特定的轨道。我可以做到这一点。
但是在曲目完成后播放停止。我希望 Spotify 播放专辑的以下曲目。有没有办法这样做?
【问题讨论】:
我还没有过多地弄乱播放器状态(只抓取封面艺术 uri),但这是我的想法。
我会首先订阅播放器状态以查看播放器发生了什么。如果暂停,我会播放您正在谈论或想要谈论的专辑。这是一个可能有用的小例子。
SpotifyAppRemote mSpotifyAppRemote; // The app remote
/* For mAppRemoteSet the connection parameters */
connectionParams = new ConnectionParams.Builder(CLIENT_ID)
.setRedirectUri(REDIRECT_URI)
.showAuthView(true)
.build();
/* Connect to SpotifyAppRemote */
SpotifyAppRemote.connect(this, connectionParams, new Connector.ConnectionListener() {
@Override
public void onConnected(SpotifyAppRemote spotifyAppRemote) {
mSpotifyAppRemote = spotifyAppRemote;
Log.d(TAG, "App remote Connected!");
connected();
@Override
public void onFailure(Throwable throwable) {
Log.e(TAG, throwable.getMessage(), throwable);
// Hanfle errors here
}
});
}
public connected() {
/* Subscribe to the PlayerState */
mSpotifyAppRemote.getPlayerApi()
.subscribeToPlayerState()
.setEventCallback(playerState -> {
if (playerState.isPaused) {
mSpotifyAppRemote.getPlayerApi().play("ALBUM URI");
}
});
}
其中“CLIENT_ID”和“REDIRECT_URI”特定于您在仪表板中已在代码中定义的内容。
其中“ALBUM URI”是您在播放您提到的第一首歌曲后要播放的专辑的特定 ID。
您也可以播放特定曲目,然后将专辑的偏移量设置为开头,如果特定曲目位于专辑的中间、结尾等位置,则重新开始整张专辑。
我仍在学习 sdk 及其提供的许多选项,所以如果这完全不相关或没有帮助,我提前道歉。
【讨论】: