Example #1
0
        private static async Task <ToastNotification> BuildToast(Music music, MediaPlaybackState state, NotificationDisplayMode display)
        {
            string toastTag = null;

            switch (state)
            {
            case MediaPlaybackState.Paused:
                toastTag = ToastTagPlaying;
                break;

            case MediaPlaybackState.Playing:
                toastTag = ToastTagPaused;
                break;
            }

            var toastContent = BuildToastContent(music, state, display);
            // Create the toast notification
            ToastNotification toast = new ToastNotification(toastContent.GetXml())
            {
                Tag   = toastTag,
                Group = ToastGroup,
                Data  = new NotificationData()
                {
                    SequenceNumber = 0
                },
                ExpiresOnReboot = true
            };

            if (Settings.settings.ShowLyricsInNotification)
            {
                await LyricsHelper.SetLyrics();

                toast.Data.Values["Lyrics"] = LyricsHelper.GetLyrics();
            }
            if (display == NotificationDisplayMode.Quick)
            {
                toast.ExpirationTime = DateTime.Now.AddSeconds(Math.Min(10, music.Duration));
            }
            //toast.Dismissed += (sender, args) => HideToast("Dismissed");
            toast.Data.Values["MediaControlPosition"]     = MediaHelper.Progress.ToString();
            toast.Data.Values["MediaControlPositionTime"] = MusicDurationConverter.ToTime(MediaHelper.Position);
            return(toast);
        }
Example #2
0
        private static void UpdateToast()
        {
            if (!MediaHelper.IsPlaying || CurrentToastMap.Count == 0)
            {
                return;
            }
            if (!IsToastActive(MediaHelper.CurrentMusic, MediaPlaybackState.Playing))
            {
                return;
            }
            // Create NotificationData and make sure the sequence number is incremented
            // since last update, or assign 0 for updating regardless of order
            var data = new NotificationData {
                SequenceNumber = 0
            };

            data.Values["MediaControlPosition"]     = MediaHelper.Progress.ToString();
            data.Values["MediaControlPositionTime"] = MusicDurationConverter.ToTime(MediaHelper.Position);
            data.Values["Lyrics"] = Settings.settings.ShowLyricsInNotification ? LyricsHelper.GetLyrics() : "";

            // Update the existing notification's data by using tag/group
            Notifier.Update(data, ToastTagPaused, ToastGroup);
        }