示例#1
0
    private void OnToggleRepeat()
    {
        SpotifyClient           client  = SpotifyService.Instance.GetSpotifyClient();
        CurrentlyPlayingContext context = this.GetCurrentContext();

        if (client != null && context != null)
        {
            // Get current shuffle state
            string currentShuffleState = context.RepeatState;

            // Determine next shuffle state
            PlayerSetRepeatRequest.State newState = PlayerSetRepeatRequest.State.Off;
            switch (currentShuffleState)
            {
            case "off":
                newState = PlayerSetRepeatRequest.State.Track;
                break;

            case "track":
                newState = PlayerSetRepeatRequest.State.Context;
                break;

            case "context":
                newState = PlayerSetRepeatRequest.State.Off;
                break;

            default:
                Debug.LogError($"Unknown Shuffle State '{currentShuffleState}'");
                break;
            }

            // Build request and send
            PlayerSetRepeatRequest request = new PlayerSetRepeatRequest(newState);
            client.Player.SetRepeat(request);
        }
    }
示例#2
0
 public async Task <bool> SetRepeat(PlayerSetRepeatRequest.State state)
 {
     return(await spotify.Player.SetRepeat(new PlayerSetRepeatRequest(state)));
 }