Esempio n. 1
0
        public override void WireMessages()
        {
            Messenger.Default.Register <NotificationMessage <List <PlaylistItem> > >(this, m =>
            {
                if (m.Notification.Equals(Constants.Messages.AddToPlaylistMsg))
                {
                    _playlistHelper.AddToPlaylist(m.Content);

                    Log.Info("Adding {0} item(s) to the playlist", m.Content.Count);
                }

                if (m.Notification.Equals(Constants.Messages.SetPlaylistAsMsg))
                {
                    _playlistHelper.ClearPlaylist();

                    _playlistHelper.AddToPlaylist(m.Content);

                    _navigationService.NavigateTo("/Views/NowPlayingView.xaml");

                    if (BackgroundAudioPlayer.Instance.PlayerState != PlayState.Playing)
                    {
                        BackgroundAudioPlayer.Instance.Play();
                    }
                }

                if (m.Notification.Equals(Constants.Messages.PlaylistPageLeftMsg))
                {
                    if (_playlistChecker.IsEnabled)
                    {
                        _playlistChecker.Stop();
                    }
                }
            });
        }
        public override void WireMessages()
        {
            Messenger.Default.Register <NotificationMessage <List <PlaylistItem> > >(this, async m =>
            {
                if (m.Notification.Equals(Constants.Messages.AddToPlaylistMsg))
                {
                    await _playlistHelper.AddToPlaylist(m.Content);

                    Log.Info("Adding {0} item(s) to the playlist", m.Content.Count);
                }

                if (m.Notification.Equals(Constants.Messages.SetPlaylistAsMsg))
                {
                    BackgroundAudioPlayer.Instance.Stop();
                    BackgroundAudioPlayer.Instance.Track = null;

                    await _playlistHelper.ClearPlaylist();

                    await _playlistHelper.AddToPlaylist(m.Content);

                    var isNowPlaying = await PlayPause();

                    NavigationService.NavigateTo(Constants.Pages.NowPlayingView);

                    if (!isNowPlaying)
                    {
                        BackgroundAudioPlayer.Instance.Play();
                    }
                }

                if (m.Notification.Equals(Constants.Messages.PlaylistPageLeftMsg))
                {
                    if (_playlistChecker.IsEnabled)
                    {
                        _playlistChecker.Stop();
                    }
                }
            });

            Messenger.Default.Register <NotificationMessage>(this, m =>
            {
                if (m.Notification.Equals(Constants.Messages.ClearNowPlayingMsg))
                {
                    NowPlayingItem = null;
                }
            });

            Messenger.Default.Register <NowPlayingMessage>(this, m =>
            {
            });
        }