【发布时间】:2016-08-01 00:26:36
【问题描述】:
我在让 Spotify 播放列表与 Beta 版 Spotify SDK 一起播放时遇到了一些问题。在某种程度上,我在使用 Spotify Player 类播放时关注this tutorial。但是,与示例不同的是,我想播放用户提供的曲目和播放列表,因此我必须收集用户曲目和播放列表数据,我已经使用 Kaaes Android Web Wrapper 完成了这项工作。收集了我需要的数据后,我尝试构建 Spotify 播放器(这似乎构建得很好),然后从一个单独的方法中,尝试播放曲目或播放列表。有趣的是,只有在构建过程中调用它(就像在教程中一样)时,我才能播放曲目,但不能从其他方法调用,而且我根本无法播放播放列表。尝试播放以下内容的播放列表时出现错误:
com.spotify.sdk.android.player.NativeSpotifyException: Failed SpPlayUri with error code 5 (An unexpected argument value was passed to a function)
我传递给 play 方法的播放列表语法如下:
spotify:playlist:4vDeSXEwfHMYOuQaTtwlUK
类似于track的:
spotify:track:2TpxZ7JUBn3uw46aR7qd6V
当然,这可能是不正确的,但很难在网上找到如何在 Android SDK 上播放播放列表的示例。那么谁能告诉我如何播放播放列表以及如何在 Spotify Player 对象上播放内容,尤其是远离 Player 构建器?我将在下面提供我工作的一些相关部分。 FWIW,我正在处理来自另一个活动的身份验证,它还没有给我带来太多问题......
private PlayerState state;
private Player player;
...
public void buildPlayer(){
//start a Spotify player
Config playerConfig = new Config(this, token, client_id);
Spotify.getPlayer(playerConfig, this, new Player.InitializationObserver() {
@Override
public void onInitialized(Player p) {
player = p;
player.addPlayerNotificationCallback(SpotifyPlayer.this);
player.setPlaybackBitrate(PlaybackBitrate.BITRATE_NORMAL);
player.getPlayerState(new PlayerStateCallback() {
@Override
public void onPlayerState(PlayerState playerState) {
state = playerState;
}
});
}
@Override
public void onError(Throwable throwable) {
Log.e(ID, "Could not initialize player: " + throwable.getMessage());
}
});
}
...
public void test(){
try {
player.play("spotify:track:2TpxZ7JUBn3uw46aR7qd6V");
//oddly enough, the track fails to play here, but not if I have this line in the builder
}catch (Exception e){
System.out.println("player failed to play");
e.printStackTrace();
}
}
这堂课还有更多内容,但现在这些都不应该干扰。我期待听到您的建议。
【问题讨论】:
标签: android sdk wrapper spotify