Spotify SDK神秘地无法播放某些歌曲

时间:2017-01-14 04:44:40

标签: android spotify

我一直在尝试创建围绕Spotify Android SDK构建的音乐应用。

出于某种原因,当播放某些歌曲时,Spotify播放器的行为就好像一切正​​常,但不会播放音乐。这仅发生在问题跟踪的约90%的时间。其他10%的时间它会发挥得很好。

据我所知,这个问题只发生在短(<30s)曲目上。

关于成功游戏和不成功游戏之间的唯一区别是kSpPlaybackNotifyTrackChanged仅在音乐实际播放时被调用。

没有错误消息,即使播放onSuccess()也会被调用。

我的地区都有这两首歌。

下面是一个简单的测试文件,我把它放在一起测试问题,而不用担心我的代码出现问题。甚至(似乎)消除了任何外部因素,问题仍然存在。对playUri(...)的调用在onLoggedIn()内。

public class ActivityHost extends ActivityPlayer implements Player.NotificationCallback, ConnectionStateCallback, Player.OperationCallback
{

public static final String CLIENT_ID = "ad5cd6a8c83843e19eb8cbf67663a3a3";
public static final String REDIRECT_URI = "auxparty-spotify://callback";

private static final int REQUEST_CODE = 4321;

Player mPlayer;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_host);

    AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(CLIENT_ID,
            AuthenticationResponse.Type.TOKEN,
            REDIRECT_URI);
    builder.setScopes(new String[]{"streaming"});
    AuthenticationRequest request = builder.build();

    AuthenticationClient.openLoginActivity(this, REQUEST_CODE, request);

    initializeViews();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
    super.onActivityResult(requestCode, resultCode, intent);

    // Check if result comes from the correct activity
    if (requestCode == REQUEST_CODE)
    {
        AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, intent);
        if (response.getType() == AuthenticationResponse.Type.TOKEN)
        {
            String token = response.getAccessToken();

            Config playerConfig = new Config(getApplicationContext(), token, ActivityHost.CLIENT_ID);
            Spotify.getPlayer(playerConfig, this, new SpotifyPlayer.InitializationObserver()
            {
                @Override
                public void onInitialized(SpotifyPlayer spotifyPlayer)
                {
                    Log.d("auxparty-spotify", "Player initialized");
                    mPlayer = spotifyPlayer;
                    mPlayer.addConnectionStateCallback(ActivityHost.this);
                    mPlayer.addNotificationCallback(ActivityHost.this);
                }

                @Override
                public void onError(Throwable throwable)
                {
                    Log.e("auxparty-spotify", "Could not initialize player: " + throwable.getMessage());
                }
            });
        }
    }
}

@Override
public void onLoggedIn() {
    Log.d("auxparty-spotify", "User logged in");

    //Player usually fails when this song is played
    mPlayer.playUri(ActivityHost.this, "spotify:track:008GDaR710wy4nlvXh7Lwm", 0, 0); 


    //Player succeeds when this song is played 
    mPlayer.playUri(ActivityHost.this, "spotify:track:077OhUjy58qkjscrXjW696", 0, 0); 
}

@Override
public void onPlaybackEvent(PlayerEvent playerEvent)
{
    Log.d("auxparty-spotify", "Playback event received: " + playerEvent.name());

    switch (playerEvent)
    {
        // Handle event type as necessary
        default:
            break;
    }
}

@Override
public void onPlaybackError(com.spotify.sdk.android.player.Error error) {
    Log.d("auxparty-spotify", "Playback error received: " + error.name());
    switch (error) {
        // Handle error type as necessary
        default:
            break;
    }
}

@Override
public void onLoggedOut() {
    Log.d("auxparty-spotify", "User logged out");
}

@Override
public void onLoginFailed(com.spotify.sdk.android.player.Error error) {
    Log.d("auxparty-spotify", "Login failed");
}

@Override
public void onTemporaryError() {
    Log.d("auxparty-spotify", "Temporary error occurred");
}

@Override
public void onConnectionMessage(String message) {
    Log.d("auxparty-spotify", "Received connection message: " + message);
}

@Override
public void onError(Error error)
{
    Log.d("auxparty-spotify", error.toString());
}

@Override
public void onSuccess()
{
    Log.d("auxparty-spotify", "playback success");
}

@Override
protected void onDestroy() {
    Spotify.destroyPlayer(this);
    super.onDestroy();
}
}

谢谢大家的帮助!

0 个答案:

没有答案