Exemple #1
0
        private static ToastContent BuildToastContent(Music music, MediaPlaybackState state, NotificationDisplayMode display)
        {
            ToastButton controlButton = null;

            switch (state)
            {
            case MediaPlaybackState.Paused:
                controlButton = BuildToastButton("Play");
                break;

            case MediaPlaybackState.Playing:
                controlButton = BuildToastButton("Pause");
                break;
            }
            var toastContent = new ToastContent()
            {
                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        Children =
                        {
                            new AdaptiveText()
                            {
                                Text = music.GetToastText()
                            },
                            new AdaptiveProgressBar()
                            {
                                Value = new BindableProgressBarValue("MediaControlPosition"),
                                ValueStringOverride = MusicDurationConverter.ToTime(music.Duration),
                                Title  = new BindableString("Lyrics"),
                                Status = new BindableString("MediaControlPositionTime")
                            }
                        }
                    }
                },
                Actions = new ToastActionsCustom()
                {
                    Buttons =
                    {
                        controlButton, BuildToastButton("Next")
                    }
                },
                ActivationType = ToastActivationType.Background,
                Launch         = "Launch",
                Audio          = SlientToast,
                Scenario       = display == NotificationDisplayMode.Reminder || state == MediaPlaybackState.Paused ? ToastScenario.Reminder : ToastScenario.Default
            };

            return(toastContent);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }