Esempio n. 1
0
        /// <summary>
        /// Attach Get User Currently Playing Commands
        /// </summary>
        /// <param name="client">Spotify Sdk Client</param>
        /// <param name="response">Currently Playing Response</param>
        public static void AttachGetUserCurrentlyPlayingCommands(
            this ISpotifySdkClient client,
            CurrentlyPlayingResponse response)
        {
            var isAttach = client.Config.IsAttachGetUserCurrentlyPlayingCommands;

            if (isAttach && response != null)
            {
                // Attach User Currently Playing Item Commands
                client.AttachUserCurrentlyPlayingItemCommands(response, isAttach);
                // Attach Device Commands
                client.AttachGetDeviceCommands(response.Device, isAttach);
                // Toggle Shuffle For User’s Playback
                response.UserPlaybackShuffleCommand = new GenericCommand <CurrentlyPlayingResponse>(
                    client.UserPlaybackShuffleHandler);
                // Set Repeat Mode On User’s Playback
                response.UserPlaybackRepeatCommand = new GenericCommand <CurrentlyPlayingResponse>(
                    client.UserPlaybackRepeatHandler);
                // Set Repeat Off For User’s Playback
                response.UserPlaybackRepeatOffCommand = new GenericCommand <CurrentlyPlayingResponse>(
                    client.UserPlaybackRepeatOffHandler);
                // Set Repeat Track For User’s Playback
                response.UserPlaybackRepeatTrackCommand = new GenericCommand <CurrentlyPlayingResponse>(
                    client.UserPlaybackRepeatTrackHandler);
                // Set Repeat Context For User’s Playback
                response.UserPlaybackRepeatContextCommand = new GenericCommand <CurrentlyPlayingResponse>(
                    client.UserPlaybackRepeatContextHandler);
                // Set Seek For User's Playback
                response.UserPlaybackSeekCommand = new GenericCommand <int>(
                    client.UserPlaybackSeekHandler);
                // Set Volume For User's Playback
                response.UserPlaybackVolumeCommand = new GenericCommand <int>(
                    client.UserPlaybackVolumeHandler);
            }
        }
 /// <summary>
 /// Toggle Shuffle For User’s Playback
 /// </summary>
 /// <param name="client">Spotify Sdk Client</param>
 /// <param name="response">Currently Playing Response</param>
 public static async void UserPlaybackShuffleHandler(
     this ISpotifySdkClient client,
     CurrentlyPlayingResponse response) =>
 await client.SetUserPlaybackAsync(
     response.ShuffleState?
     PlaybackType.ShuffleOn :
     PlaybackType.ShuffleOff);
        /// <summary>
        /// Set Repeat Mode On User’s Playback Handler
        /// </summary>
        /// <param name="client">Spotify Sdk Client</param>
        /// <param name="response">Currently Playing Response</param>
        public static async void UserPlaybackRepeatHandler(
            this ISpotifySdkClient client,
            CurrentlyPlayingResponse response)
        {
            // States are Off, Track and Context
            switch (response.RepeatState)
            {
            case "off":
                // Track is Next State if Allowed
                if (response?.Actions?.Allows?.IsTogglingRepeatTrackAllowed ?? false)
                {
                    await client.SetUserPlaybackAsync(PlaybackType.RepeatTrack);
                }
                // Or Context is Next State if Allowed
                else if (response?.Actions?.Allows?.IsTogglingRepeatContextAllowed ?? false)
                {
                    await client.SetUserPlaybackAsync(PlaybackType.RepeatContext);
                }
                break;

            case "track":
                // Context is Next State if Allowed
                if (response?.Actions?.Allows?.IsTogglingRepeatContextAllowed ?? false)
                {
                    await client.SetUserPlaybackAsync(PlaybackType.RepeatContext);
                }
                // Or Off is the Next State
                else
                {
                    await client.SetUserPlaybackAsync(PlaybackType.RepeatOff);
                }
                break;

            case "context":
                // Off is the Next State
                await client.SetUserPlaybackAsync(PlaybackType.RepeatOff);

                break;
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Set Current User Extended Properties
 /// </summary>
 /// <param name="client">Spotify Sdk Client</param>
 /// <param name="response">Current User Response</param>
 public static void SetCurrentlyPlayingExtended(this ISpotifySdkClient client, CurrentlyPlayingResponse response)
 {
     if (response?.Device != null)
     {
         client.CurrentDevice = response.Device;
     }
 }
 /// <summary>
 /// Resume a User's Playback Handler
 /// </summary>
 /// <param name="client">Spotify Sdk Client</param>
 /// <param name="response">Currently Playing Response</param>
 public static async void UserPlaybackResumeHandler(
     this ISpotifySdkClient client,
     CurrentlyPlayingResponse response) =>
 await client.SetUserPlaybackAsync(PlaybackType.Resume);