Пример #1
0
        public static async void UpdateLiveTile()
        {
            try
            {
                if (LocalConfiguration.LiveTileDesign == LiveTileDesign.Disabled)
                {
                    ClearLiveTile();
                    return;
                }

                var artistPhoto = await SongImageProvider.GetArtistArt(PlayStatusTracker.LastPlayStatus.ArtistId);

                var albumPhoto = await SongImageProvider.GetAlbumArt(PlayStatusTracker.LastPlayStatus.AlbumId);

                var template = GetLiveTileTemplate(LocalConfiguration.LiveTileDesign)
                               .Replace("{albumName}", WebUtility.HtmlEncode(PlayStatusTracker.LastPlayStatus.AlbumName))
                               .Replace("{artistName}", WebUtility.HtmlEncode(PlayStatusTracker.LastPlayStatus.ArtistName))
                               .Replace("{songName}", WebUtility.HtmlEncode(PlayStatusTracker.LastPlayStatus.SongName))
                               .Replace("{artistPhoto}", WebUtility.HtmlEncode(artistPhoto))
                               .Replace("{albumPhoto}", WebUtility.HtmlEncode(albumPhoto));

                UpdateTileWithTemplate(template);

                logger.Info("Live tile updated.");
            }
            catch (Exception ex)
            {
                logger.Warn("UpdateLiveTile failed: " + ex.ToString());
            }
        }
Пример #2
0
        private static async Task UpdateMediaControls()
        {
            if (MediaControls == null)
            {
                return;
            }

            var hash = $"{LastPlayStatus.IsPlaying};{LastPlayStatus.SongName};{LastPlayStatus.AlbumId};{LastPlayStatus.ArtistId}".GetHashCode();

            if (lastMediaControlUpdateHash == hash)
            {
                return;
            }

            lastMediaControlUpdateHash = hash;

            logger.Info("Updating MediaControls...");

            MediaControls.PlaybackStatus = (LastPlayStatus.IsPlaying) ? MediaPlaybackStatus.Playing : MediaPlaybackStatus.Paused;
            MediaControls.DisplayUpdater.MusicProperties.Title      = LastPlayStatus.SongName;
            MediaControls.DisplayUpdater.MusicProperties.AlbumTitle = LastPlayStatus.AlbumName;
            MediaControls.DisplayUpdater.MusicProperties.Artist     = LastPlayStatus.ArtistName;

            try
            {
                var albumArt = await SongImageProvider.GetAlbumArt(LastPlayStatus.AlbumId);

                if (string.IsNullOrEmpty(albumArt))
                {
                    MediaControls.DisplayUpdater.Thumbnail = null;
                }
                else
                {
                    MediaControls.DisplayUpdater.Thumbnail = RandomAccessStreamReference.CreateFromUri(new Uri(albumArt));
                }
            }
            catch { }

            MediaControls.DisplayUpdater.Update();

            logger.Info("MediaControls updated.");
        }
Пример #3
0
        public static async Task <TileImageCollection> GetTileImages(string pageUrl)
        {
            try
            {
                if (pageUrl.ToLower().StartsWith("https://open.spotify.com/playlist/"))
                {
                    string playlistId = pageUrl.Substring("https://open.spotify.com/playlist/".Length);
                    if (playlistId.Contains('/'))
                    {
                        playlistId = playlistId.Substring(0, playlistId.IndexOf('/') - 1);
                    }

                    var image = await ImageSaveHelper.GetAndSaveTileOriginalImage(await SongImageProvider.GetPlaylistArt(playlistId));

                    var tileImages = await CreateTileImages(image);

                    await(await StorageFile.GetFileFromApplicationUriAsync(image)).DeleteAsync();

                    return(tileImages);
                }
                else if (pageUrl.ToLower().StartsWith("https://open.spotify.com/artist/"))
                {
                    string artistId = pageUrl.Substring("https://open.spotify.com/artist/".Length);
                    if (artistId.Contains('/'))
                    {
                        artistId = artistId.Substring(0, artistId.IndexOf('/') - 1);
                    }

                    var image = await ImageSaveHelper.GetAndSaveTileOriginalImage(await SongImageProvider.GetArtistArt(artistId));

                    var tileImages = await CreateTileImages(image);

                    await(await StorageFile.GetFileFromApplicationUriAsync(image)).DeleteAsync();

                    return(tileImages);
                }
                else if (pageUrl.ToLower().StartsWith("https://open.spotify.com/album/"))
                {
                    string albumId = pageUrl.Substring("https://open.spotify.com/album/".Length);
                    if (albumId.Contains('/'))
                    {
                        albumId = albumId.Substring(0, albumId.IndexOf('/') - 1);
                    }

                    var image = await ImageSaveHelper.GetAndSaveTileOriginalImage(await SongImageProvider.GetAlbumArt(albumId));

                    var tileImages = await CreateTileImages(image);

                    await(await StorageFile.GetFileFromApplicationUriAsync(image)).DeleteAsync();

                    return(tileImages);
                }
            }
            catch (Exception ex)
            {
                logger.Info("GetTileImage failed: " + ex.ToString());
            }

            return(null);
        }