Пример #1
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            var app = (App)Application.Current;

            // load artwork if available
            if (Track != null && Track.Thumb != null)
            {
                BitmapImage bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.UriSource   = app.plexClient.GetPhotoTranscodeUrl(Track.Thumb, 50, 50);
                bitmap.CacheOption = BitmapCacheOption.Default;
                bitmap.EndInit();

                imageArtwork.Source = bitmap;

                imageArtwork.Visibility     = Visibility.Visible;
                imageArtworkNone.Visibility = Visibility.Collapsed;
            }
            else
            {
                imageArtwork.Visibility     = Visibility.Collapsed;
                imageArtworkNone.Visibility = Visibility.Visible;
            }

            var playbackManager = PlaybackManager.GetInstance();

            playbackManager.PlaybackStateChanged += TrackButton_PlaybackStateChanged;
            TrackButton_PlaybackStateChanged(playbackManager.Track, new EventArgs());
        }
Пример #2
0
        private void Playback_PlaybackTick(object sender, EventArgs e)
        {
            var app = (App)System.Windows.Application.Current;

            Task.Factory.StartNew(() =>
            {
                var playback = PlaybackManager.GetInstance();

                doNotTriggerEvent = true;

                if (playback.Track != null)
                {
                    sliderPosition.Value     = playback.Position;
                    sliderPosition.Maximum   = playback.Track.Duration;
                    sliderPosition.IsEnabled = true;
                }
                else
                {
                    sliderPosition.Value     = 0;
                    sliderPosition.Maximum   = 1;
                    sliderPosition.IsEnabled = false;
                }

                doNotTriggerEvent = false;
            }, CancellationToken.None, TaskCreationOptions.None, app.uiContext);
        }
Пример #3
0
        private void TrackButton_Click(object sender, RoutedEventArgs e)
        {
            var index = ItemsControlHelper.FindIndexByItemChild(panelTracks, sender as DependencyObject);

            if (index == -1)
            {
                return;
            }

            var playQueue = PlayQueueManager.GetInstance();
            var track     = playQueue.FromTracks(Tracks.ToArray(), index);

            playQueue.AddPlayedIndex();

            var playback = PlaybackManager.GetInstance();

            playback.Play(track);

            var app = (App)Application.Current;

            app.config.LastPlaylist = Playlist.MetadataUrl;

            var mainWindow = MainWindow.GetInstance();

            mainWindow.GoToPlayQueue();
        }
Пример #4
0
        private NotificationWindow(PlexTrack track)
        {
            InitializeComponent();
            tokenSource = new CancellationTokenSource();

            Title = track.Title + " - " + track.Artist.Title;

            // load artwork
            var app = (App)System.Windows.Application.Current;

            if (track.Thumb == null)
            {
                imageArtwork.Visibility     = Visibility.Collapsed;
                imageArtworkNone.Visibility = Visibility.Visible;
            }
            else
            {
                BitmapImage bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.UriSource   = app.plexClient.GetPhotoTranscodeUrl(track.Thumb, 50, 50);
                bitmap.CacheOption = BitmapCacheOption.Default;
                bitmap.EndInit();

                imageArtwork.Source = bitmap;

                imageArtwork.Visibility     = Visibility.Visible;
                imageArtworkNone.Visibility = Visibility.Collapsed;
            }

            var playback = PlaybackManager.GetInstance();

            playback.PlaybackTick += Playback_PlaybackTick;
        }
Пример #5
0
        private void TrackButton_PlaybackStateChanged(object sender, EventArgs e)
        {
            var app             = (App)Application.Current;
            var playbackManager = PlaybackManager.GetInstance();

            // update UI
            Task.Factory.StartNew(() =>
            {
                if (DoNotUpdatePlaying)
                {
                    return;
                }

                if (playbackManager.Track == null || Track == null || playbackManager.Track.MetadataUrl != Track.MetadataUrl || playbackManager.PlaybackState == NAudio.Wave.PlaybackState.Stopped)
                {
                    IsPlaying = false;
                }
                else
                {
                    IsPlaying = true;
                }

                button.Tag = IsPlaying;
            }, CancellationToken.None, TaskCreationOptions.None, app.uiContext);
        }
Пример #6
0
        private void UserControl_Unloaded(object sender, RoutedEventArgs e)
        {
            var playbackManager = PlaybackManager.GetInstance();

            playbackManager.PlaybackStateChanged -= PlaybackManager_PlaybackStateChanged;
            playbackManager.RepeatChanged        -= PlaybackManager_RepeatChanged;
            playbackManager.ShuffleChanged       -= PlaybackManager_ShuffleChanged;
        }
Пример #7
0
        private void Position_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            if (doNotTriggerSliderEvent)
            {
                return;
            }

            PlaybackManager.GetInstance().Position = (long)e.NewValue;
        }
Пример #8
0
        private void PlaybackManager_VolumeChanged(object sender, EventArgs e)
        {
            doNotTriggerEvent = true;

            var playbackManager = PlaybackManager.GetInstance();
            var newValue        = playbackManager.Volume * 100.0;

            sliderVolume.Value = newValue;
            textVolume.Text    = ((int)newValue).ToString();
        }
Пример #9
0
        private void Playback_PlaybackTick(object sender, EventArgs e)
        {
            var app      = (App)System.Windows.Application.Current;
            var playback = PlaybackManager.GetInstance();

            Task.Factory.StartNew(() =>
            {
                sliderPosition.Value   = playback.Position;
                sliderPosition.Maximum = playback.Track == null ? 1 : playback.Track.Duration;
            }, CancellationToken.None, TaskCreationOptions.None, app.uiContext);
        }
Пример #10
0
        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);

            // unregister event
            var playback = PlaybackManager.GetInstance();

            playback.PlaybackTick -= Playback_PlaybackTick;

            tokenSource.Cancel();
            notificationWindow = null;
        }
Пример #11
0
        private void sliderVolume_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            if (doNotTriggerEvent)
            {
                doNotTriggerEvent = false;
                return;
            }

            var playbackManager = PlaybackManager.GetInstance();

            playbackManager.Volume = (float)(e.NewValue / 100.0f);
        }
Пример #12
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (!(Application.Current is App))
            {
                return;
            }

            var playbackManager = PlaybackManager.GetInstance();

            playbackManager.VolumeChanged += PlaybackManager_VolumeChanged;

            // update UI
            PlaybackManager_VolumeChanged(playbackManager, new EventArgs());
        }
Пример #13
0
        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);

            // unregister event handler
            var playback = PlaybackManager.GetInstance();

            playback.PlaybackStateChanged -= Playback_PlaybackStateChanged;
            playback.PlaybackTick         -= Playback_PlaybackTick;
            playback.VolumeChanged        -= Playback_VolumeChanged;

            // .net will destroy this instance
            instance = null;
        }
Пример #14
0
        // PlaybackManager event handlers
        private void Playback_PlaybackStateChanged(object sender, EventArgs e)
        {
            var app = (App)System.Windows.Application.Current;

            Task.Factory.StartNew(() =>
            {
                var playback = PlaybackManager.GetInstance();

                if (playback.Track == null)
                {
                    Title = string.Empty;

                    sliderPosition.Value     = 0;
                    sliderPosition.Maximum   = 1;
                    sliderPosition.IsEnabled = false;

                    imageArtwork.Source = null;

                    imageArtwork.Visibility     = Visibility.Collapsed;
                    imageArtworkNone.Visibility = Visibility.Collapsed;
                }
                else
                {
                    Title = playback.Track.Title + " - " + playback.Track.Artist.Title;

                    // load artwork
                    if (playback.Track.Thumb == null)
                    {
                        imageArtwork.Visibility     = Visibility.Collapsed;
                        imageArtworkNone.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        BitmapImage bitmap = new BitmapImage();
                        bitmap.BeginInit();
                        bitmap.UriSource   = app.plexClient.GetPhotoTranscodeUrl(playback.Track.Thumb, 50, 50);
                        bitmap.CacheOption = BitmapCacheOption.OnDemand;
                        bitmap.EndInit();

                        imageArtwork.Source = bitmap;

                        imageArtwork.Visibility     = Visibility.Visible;
                        imageArtworkNone.Visibility = Visibility.Collapsed;
                    }
                }

                buttonPlay.Visibility  = playback.PlaybackState == NAudio.Wave.PlaybackState.Playing ? Visibility.Collapsed : Visibility.Visible;
                buttonPause.Visibility = playback.PlaybackState == NAudio.Wave.PlaybackState.Playing ? Visibility.Visible : Visibility.Collapsed;
            }, CancellationToken.None, TaskCreationOptions.None, app.uiContext);
        }
Пример #15
0
        private void UserControl_Unloaded(object sender, RoutedEventArgs e)
        {
            var playbackControl = PlaybackManager.GetInstance();

            playbackControl.StartPlaying         -= PlaybackControl_StartPlaying;
            playbackControl.PlaybackTick         -= PlaybackControl_PlaybackTick;
            playbackControl.PlaybackStateChanged -= PlaybackControl_PlaybackStateChanged;

            var upcomings = UpcomingManager.GetInstance();

            upcomings.TrackChanged -= Upcomings_TrackChanged;

            artworkResizeTokenSource.Cancel();
        }
Пример #16
0
        private void Position_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            if (doNotTriggerEvent)
            {
                return;
            }

            var app      = (App)System.Windows.Application.Current;
            var playback = PlaybackManager.GetInstance();

            Task.Factory.StartNew(() =>
            {
                playback.Position = (long)e.NewValue;
            }, CancellationToken.None, TaskCreationOptions.None, app.uiContext);
        }
Пример #17
0
        private void TrackButton_Click(object sender, RoutedEventArgs e)
        {
            var index = ItemsControlHelper.FindIndexByItemChild(panelTracks, sender as DependencyObject);

            if (index == -1)
            {
                return;
            }

            var upcomings = UpcomingManager.GetInstance();
            var track     = upcomings.Remove(index);

            var playback = PlaybackManager.GetInstance();

            playback.Play(track);
        }
Пример #18
0
        private void MenuItem_Play_Click(object sender, RoutedEventArgs e)
        {
            var button = (Component.TrackButton)((ContextMenu)((MenuItem)e.Source).Parent).PlacementTarget;
            var index  = ItemsControlHelper.FindIndexByItemChild(panelTracks, button);

            var playQueue = PlayQueueManager.GetInstance();
            var track     = playQueue.FromTracks(Tracks, index);

            playQueue.AddPlayedIndex();

            var playback = PlaybackManager.GetInstance();

            playback.Play(track);

            var mainWindow = MainWindow.GetInstance();

            mainWindow.GoToPlayQueue();
        }
Пример #19
0
        private void PlaybackControl_PlaybackTick(object sender, EventArgs e)
        {
            var app = (App)Application.Current;

            Task.Factory.StartNew(() =>
            {
                doNotTriggerSliderEvent = true;

                if (Track == null)
                {
                    sliderPosition.Value       = 0;
                    sliderPosition.Maximum     = 1;
                    sliderPosition.IsEnabled   = false;
                    textPosition.Text          = "00:00";
                    textPositionRemaining.Text = "00:00";
                    textBuffering.Visibility   = Visibility.Collapsed;
                }
                else
                {
                    var playback = PlaybackManager.GetInstance();

                    var position  = playback.Position;
                    var duration  = Track.Duration;
                    var remaining = duration - position;

                    sliderPosition.Value     = position;
                    sliderPosition.Maximum   = duration;
                    sliderPosition.IsEnabled = true;

                    int positionMinute = (int)Math.Floor(position / 60.0);
                    int positionSecond = (int)(position - positionMinute * 60.0);
                    textPosition.Text  = positionMinute.ToString().PadLeft(2, '0') + ":" + positionSecond.ToString().PadLeft(2, '0');

                    int remainingMinute        = (int)Math.Floor(remaining / 60.0);
                    int remainingSecond        = (int)(remaining - remainingMinute * 60.0);
                    textPositionRemaining.Text = remainingMinute.ToString().PadLeft(2, '0') + ":" + remainingSecond.ToString().PadLeft(2, '0');

                    textBuffering.Visibility = playback.IsBuffering ? Visibility.Visible : Visibility.Collapsed;
                }

                doNotTriggerSliderEvent = false;
            }, CancellationToken.None, TaskCreationOptions.None, app.uiContext);
        }
Пример #20
0
        private PlaybackControlWindow()
        {
            InitializeComponent();

            // hide all notification
            NotificationWindow.HideAll();

            // event handler
            var playback = PlaybackManager.GetInstance();

            playback.PlaybackStateChanged += Playback_PlaybackStateChanged;
            playback.PlaybackTick         += Playback_PlaybackTick;
            playback.VolumeChanged        += Playback_VolumeChanged;

            // invoke all event handlers
            Playback_PlaybackStateChanged(this, new EventArgs());
            Playback_PlaybackTick(this, new EventArgs());
            Playback_VolumeChanged(this, new EventArgs());
        }
Пример #21
0
        private void PlaybackManager_PlaybackStateChanged(object sender, EventArgs e)
        {
            var app = (App)Application.Current;

            Task.Factory.StartNew(() =>
            {
                var playbackManager = PlaybackManager.GetInstance();

                if (playbackManager.PlaybackState == NAudio.Wave.PlaybackState.Playing)
                {
                    buttonPlay.Visibility  = Visibility.Collapsed;
                    buttonPause.Visibility = Visibility.Visible;
                }
                else
                {
                    buttonPlay.Visibility  = Visibility.Visible;
                    buttonPause.Visibility = Visibility.Collapsed;
                }
            }, CancellationToken.None, TaskCreationOptions.None, app.uiContext);
        }
Пример #22
0
        private void TrackButton_Click(object sender, RoutedEventArgs e)
        {
            var button = (Component.TrackButton)sender;

            var index = ItemsControlHelper.FindIndexByItemChild(panelTracks, button);

            if (index == -1)
            {
                return;
            }

            skipNextCurrentChanged = true;

            var playQueue = PlayQueueManager.GetInstance();

            playQueue.Play(index);

            var playback = PlaybackManager.GetInstance();

            playback.Play(button.Track);
        }
Пример #23
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            var playbackControl = PlaybackManager.GetInstance();

            playbackControl.StartPlaying         += PlaybackControl_StartPlaying;
            playbackControl.PlaybackTick         += PlaybackControl_PlaybackTick;
            playbackControl.PlaybackStateChanged += PlaybackControl_PlaybackStateChanged;

            var upcomings = UpcomingManager.GetInstance();

            upcomings.TrackChanged += Upcomings_TrackChanged;
            Upcomings_TrackChanged(this, e);

            Track = playbackControl.Track;
            LoadArtwork();
        }
Пример #24
0
        private void PlaybackControl_PlaybackStateChanged(object sender, EventArgs e)
        {
            var app      = (App)Application.Current;
            var playback = PlaybackManager.GetInstance();

            if (playback.PlaybackState == NAudio.Wave.PlaybackState.Stopped)
            {
                Task.Factory.StartNew(() =>
                {
                    sliderPosition.Value        = 0;
                    sliderPosition.Maximum      = 1;
                    sliderPosition.IsEnabled    = false;
                    textPosition.Text           = "00:00";
                    textPositionRemaining.Text  = "00:00";
                    textBuffering.Visibility    = Visibility.Collapsed;
                    imageArtwork.Source         = null;
                    imageArtwork.Visibility     = Visibility.Collapsed;
                    imageArtworkNone.Visibility = Visibility.Collapsed;
                    Track = null;
                }, CancellationToken.None, TaskCreationOptions.None, app.uiContext);
            }
        }
Пример #25
0
        private void Shuffle_Click(object sender, RoutedEventArgs e)
        {
            var playbackManager = PlaybackManager.GetInstance();

            playbackManager.IsShuffle = !playbackManager.IsShuffle;
        }
Пример #26
0
        private void UserControl_Unloaded(object sender, RoutedEventArgs e)
        {
            var playbackManager = PlaybackManager.GetInstance();

            playbackManager.VolumeChanged -= PlaybackManager_VolumeChanged;
        }
Пример #27
0
 private void UserControl_Unloaded(object sender, RoutedEventArgs e)
 {
     PlaybackManager.GetInstance().PlaybackStateChanged -= TrackButton_PlaybackStateChanged;
 }
Пример #28
0
 private void Playback_VolumeChanged(object sender, EventArgs e)
 {
     doNotTriggerEvent  = true;
     sliderVolume.Value = Math.Ceiling(PlaybackManager.GetInstance().Volume * 100);
     doNotTriggerEvent  = false;
 }
Пример #29
0
        private void PlaybackManager_ShuffleChanged(object sender, EventArgs e)
        {
            var playbackManager = PlaybackManager.GetInstance();

            pathShuffle.Fill = new SolidColorBrush(playbackManager.IsShuffle ? Color.FromRgb(0xCC, 0x7B, 0x19) : Color.FromRgb(255, 255, 255));
        }
Пример #30
0
        private void Repeat_Click(object sender, RoutedEventArgs e)
        {
            var playbackManager = PlaybackManager.GetInstance();

            playbackManager.IsRepeat = !playbackManager.IsRepeat;
        }