Exemple #1
0
        private async Task GetDevices()
        {
            var devices = await _spotifyWebApi.GetDevicesAsync();

            if (!devices.HasError())
            {
                devices.Devices.ForEach(device =>
                {
                    var devEntity = new SpotifyDeviceEd
                    {
                        VolumePercent = device.VolumePercent,
                        DeviceName    = device.Name,
                        EntityName    = device.Name,
                        DeviceType    = device.Type,
                        IsActive      = device.IsActive,
                        IsRestricted  = device.IsRestricted
                    };

                    _ioTService.InsertEvent(devEntity);
                });
            }
            else
            {
                _logger.LogError($"Error during get Devices: {devices.Error}");
            }
        }
        public async void SendPreviousTrackCommand(SpotifyDeviceEd entity, string commandName, params object[] args)
        {
            var errorResponse = await _spotifyWebApi.SkipPlaybackToPreviousAsync(deviceId : args.Length > 0?args[0] as string : "");

            if (errorResponse.HasError())
            {
                _logger.LogError($"Error during Previous Track: {errorResponse.Error.Status} - {errorResponse.Error.Message}");
            }
        }
        public async void SendPauseCommand(SpotifyDeviceEd entity, string commandName, params object[] args)
        {
            var errorResponse = await _spotifyWebApi.PausePlaybackAsync();

            if (errorResponse.HasError())
            {
                _logger.LogError($"Error during Pause: {errorResponse.Error.Status} - {errorResponse.Error.Message}");
            }
        }
        public async void SendSetShuffleCommand(SpotifyDeviceEd entity, string commandName, params object[] args)
        {
            var state  = args[0] as string;
            var device = "";

            if (args.Length > 1)
            {
                device = args[1] as string;
            }

            var errorResponse = await _spotifyWebApi.SetShuffleAsync(bool.Parse(state), device);

            if (errorResponse.HasError())
            {
                _logger.LogError($"Error during Set Shuffle: {errorResponse.Error.Status} - {errorResponse.Error.Message}");
            }
        }
        public async void SendSetRepeatCommand(SpotifyDeviceEd entity, string commandName, params object[] args)
        {
            var state  = args[0] as string;
            var device = "";

            if (args.Length > 1)
            {
                device = args[1] as string;
            }

            var errorResponse = await _spotifyWebApi.SetRepeatModeAsync((RepeatState)Enum.Parse(typeof(RepeatState), state, true), device);

            if (errorResponse.HasError())
            {
                _logger.LogError($"Error during Set Repeat: {errorResponse.Error.Status} - {errorResponse.Error.Message}");
            }
        }
 public async void SendResumeCommand(SpotifyDeviceEd entity, string commandName, params object[] args) =>
 await SendPlayCommand(deviceId : args.Length > 0?args[0] as string : "");
 public async void SendPlayContextCommand(SpotifyDeviceEd entity, string commandName, params object[] args) =>
 await SendPlayCommand(contextUri : args[0] as string, deviceId : args.Length > 1?args[1] as string : "");