Пример #1
0
        public static async Task Desmute()
        {
            var json = await File.ReadAllTextAsync(CredentialsPath);

            var token = JsonConvert.DeserializeObject <PKCETokenResponse>(json);

            var authenticator = new PKCEAuthenticator(clientId !, token);

            authenticator.TokenRefreshed += (sender, token) => File.WriteAllText(CredentialsPath, JsonConvert.SerializeObject(token));

            var config = SpotifyClientConfig.CreateDefault()
                         .WithAuthenticator(authenticator);

            var spotify = new SpotifyClient(config);

            var me = await spotify.UserProfile.Current();

            //   Debug.WriteLine($"Welcome {me.DisplayName} ({me.Id}), you're authenticated!");

            PlayerVolumeRequest playvolumecontext = new PlayerVolumeRequest(volumeBefore);

            await spotify.Player.SetVolume(playvolumecontext);

            Mute = false;

            _server.Dispose();
        }
Пример #2
0
        public static async Task setVolume(int volume)
        {
            if (Mute)
            {
                await Desmute();
            }
            var json = await File.ReadAllTextAsync(CredentialsPath);

            var token = JsonConvert.DeserializeObject <PKCETokenResponse>(json);

            var authenticator = new PKCEAuthenticator(clientId !, token);

            authenticator.TokenRefreshed += (sender, token) => File.WriteAllText(CredentialsPath, JsonConvert.SerializeObject(token));

            var config = SpotifyClientConfig.CreateDefault()
                         .WithAuthenticator(authenticator);

            var spotify = new SpotifyClient(config);

            var me = await spotify.UserProfile.Current();

            //   Debug.WriteLine($"Welcome {me.DisplayName} ({me.Id}), you're authenticated!");
            int atualpercent = spotify.Player.GetCurrentPlayback().Result.Device.VolumePercent.GetValueOrDefault();
            int result       = atualpercent + volume;
            PlayerVolumeRequest playvolumecontext = new PlayerVolumeRequest(result);

            await spotify.Player.SetVolume(playvolumecontext);


            _server.Dispose();
            //  Environment.Exit(0);
        }
Пример #3
0
        public static async Task <bool> MuteDesmute()
        {
            var json = await File.ReadAllTextAsync(CredentialsPath);

            var token = JsonConvert.DeserializeObject <PKCETokenResponse>(json);

            var authenticator = new PKCEAuthenticator(clientId !, token);

            authenticator.TokenRefreshed += (sender, token) => File.WriteAllText(CredentialsPath, JsonConvert.SerializeObject(token));

            var config = SpotifyClientConfig.CreateDefault()
                         .WithAuthenticator(authenticator);

            var spotify = new SpotifyClient(config);

            var me = await spotify.UserProfile.Current();


            if (spotify.Player.GetCurrentPlayback().Result == null)
            {
                return(false);
            }

            if (isClicked)
            {
                var volumeatual = spotify.Player.GetCurrentPlayback().Result.Device.VolumePercent.GetValueOrDefault();
                if (volumeatual != 0)
                {
                    volumeBefore = volumeatual;
                }
                PlayerVolumeRequest playvolumecontext = new PlayerVolumeRequest(0);
                await spotify.Player.SetVolume(playvolumecontext);

                isClicked = false;
                Mute      = true;
                _server.Dispose();
                return(true);
            }
            else
            {
                PlayerVolumeRequest playvolume = new PlayerVolumeRequest(volumeBefore);
                await spotify.Player.SetVolume(playvolume);

                isClicked = true;
                Mute      = false;
                _server.Dispose();
                return(false);
            }
        }
        public void ToggleMute()
        {
            Device currentDevice = PlaybackContext.Device;
            PlayerVolumeRequest volRequest;

            if (currentDevice.VolumePercent != 0)
            {
                // VolumePercent is nullable for whatever reason - assume to be 100 if null
                mLastVolume = (currentDevice.VolumePercent != null ? (int)currentDevice.VolumePercent : 100);
                volRequest  = new PlayerVolumeRequest(0);
            }
            else
            {
                volRequest = new PlayerVolumeRequest(mLastVolume);
            }

            _spotifyClient.Player.SetVolume(volRequest).GetAwaiter().GetResult();;
        }
Пример #5
0
 public async void SetVolume(int volume)
 {
     try
     {
         if (volume > 100 || volume < 0)
         {
             return;
         }
         var request = new PlayerVolumeRequest(volume)
         {
             DeviceId = _deviceId
         };
         await _spotifyClient.Player.SetVolume(request);
     }
     catch (APIException)
     {
     }
 }
Пример #6
0
    private void OnToggleMute()
    {
        SpotifyClient client  = SpotifyService.Instance.GetSpotifyClient();
        var           context = GetCurrentContext();

        if (context != null && client != null)
        {
            int?  volume = context.Device.VolumePercent;
            int   targetVolume;
            Image muteImg = _muteButton.transform.GetChild(0).GetComponent <Image>();
            if (volume.HasValue && volume > 0)
            {
                // Set target volume to 0, sprite to muted
                targetVolume   = 0;
                muteImg.sprite = _muteSprite;
                // Save current volume for unmute press
                _volumeLastValue = volume.Value;
            }
            else
            {
                // Set target to last volume value before mute
                if (_volumeLastValue > 0)
                {
                    targetVolume     = _volumeLastValue;
                    _volumeLastValue = -1;
                }
                else
                {
                    // If no value, use default value
                    targetVolume = 25;
                }

                // Update sprite
                muteImg.sprite = _unmuteSprite;
            }

            // Send request
            PlayerVolumeRequest request = new PlayerVolumeRequest(targetVolume);
            client.Player.SetVolume(request);
        }
    }
Пример #7
0
 Task <bool> IPlayerClient.SetVolume(PlayerVolumeRequest request)
 => throw new NotImplementedException();
        public void SetVolume(int volumePercent = 0)
        {
            var volRequest = new PlayerVolumeRequest(volumePercent);

            _spotifyClient.Player.SetVolume(volRequest).GetAwaiter().GetResult();;
        }