Exemplo n.º 1
0
        public async Task <SongRequestCurrentlyPlayingModel> GetStatus()
        {
            try
            {
                SpotifyCurrentlyPlayingModel currentlyPlaying = await ChannelSession.Services.Spotify.GetCurrentlyPlaying();

                if (currentlyPlaying != null && currentlyPlaying.ID != null)
                {
                    SongRequestCurrentlyPlayingModel result = new SongRequestCurrentlyPlayingModel()
                    {
                        ID         = currentlyPlaying.ID,
                        URI        = currentlyPlaying.Uri,
                        Name       = currentlyPlaying.ToString(),
                        AlbumImage = (!string.IsNullOrEmpty(currentlyPlaying.Album?.ImageLink)) ? currentlyPlaying.Album?.ImageLink : SpotifyDefaultAlbumArt,
                        Type       = SongRequestServiceTypeEnum.Spotify,
                        Progress   = currentlyPlaying.CurrentProgress,
                        Length     = currentlyPlaying.Duration,
                        Volume     = currentlyPlaying.Volume,
                    };

                    if (currentlyPlaying.IsPlaying)
                    {
                        result.State = SongRequestStateEnum.Playing;
                    }
                    else if (currentlyPlaying.CurrentProgress > 0)
                    {
                        result.State = SongRequestStateEnum.Paused;
                    }
                    else
                    {
                        result.State = SongRequestStateEnum.Ended;
                    }

                    return(result);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
            return(null);
        }
Exemplo n.º 2
0
        public async Task PauseResume()
        {
            try
            {
                SpotifyCurrentlyPlayingModel currentlyPlaying = await ChannelSession.Services.Spotify.GetCurrentlyPlaying();

                if (currentlyPlaying != null && currentlyPlaying.ID != null)
                {
                    if (currentlyPlaying.IsPlaying)
                    {
                        await this.Pause();
                    }
                    else
                    {
                        await this.Resume();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }
        }