Example #1
0
        /// <summary>
        /// Replaces the entire track queue with a single song, queuing up the other items in the same track container.
        /// You should check the UserMutatedQueue property before performing a destructive replacement.
        /// </summary>
        /// <param name="t">The song.</param>
        /// <param name="a">The track container that holds the song.</param>
        public void ReplaceAllWithSong(Track t, ITrackContainer a)
        {
            Contract.Requires(t != null);
            Contract.Requires(a != null);
            Contract.Requires(a.TrackList != null);
            Contract.Requires(a.TrackList.Count != 0);

            _trackList.BatchChanges();

            Clear();

            var items = a.TrackList.AsParallel().AsOrdered().Select(x => x.UniqueTrack());

            _trackList.Enqueue(items);

            int trackOffset = Math.Max(0, a.IndexOf(t));

            _trackList.Dequeue(trackOffset);

            _trackList.FlushChanges();
        }
Example #2
0
        /// <summary>
        /// Like OnNavigatedTo(), but runs after the whole UI has already been prepared.
        /// Place any loading code here that requires the UI to be completely loaded.
        /// </summary>
        private async void page_Loaded(object sender, RoutedEventArgs e)
        {
            // Initialize the controller if necessary
            if (AudioController.Default.Status == AudioControllerStatus.NotReady)
            {
                DependencyObject rootGrid         = Windows.UI.Xaml.Media.VisualTreeHelper.GetChild(Window.Current.Content, 0);
                MediaElement     rootMediaElement = (MediaElement)Windows.UI.Xaml.Media.VisualTreeHelper.GetChild(rootGrid, 0);
                AudioController.Default.Ready(rootMediaElement);
            }

            // Initialize animations
            VisualStateManager.GoToState(this, "NoOverlayAlbum", false);
            VisualStateManager.GoToState(this, "NoOverlayQueue", false);
            VisualStateManager.GoToState(this, "NoOverlayMessage", false);

            Type            pageMode            = typeof(Album);
            double          scroll              = 0d;
            ITrackContainer navigationContainer = null;
            Track           navigationItem      = null;

            if (_navigationParameter.HasValue && LibraryItemToken.VerifyToken(_navigationParameter.Value))
            {
                var navigationParameter = LibraryItemToken.GetItem(_navigationParameter.Value);

                // If there is a navigationParameter, use it, and ignore the pageState!
                if (navigationParameter is Album)
                {
                    pageMode            = typeof(Album);
                    navigationContainer = navigationParameter as ITrackContainer;
                }
                else if (navigationParameter is Playlist)
                {
                    pageMode            = typeof(Playlist);
                    navigationContainer = navigationParameter as ITrackContainer;
                }
                else if (navigationParameter is Track)
                {
                    pageMode       = typeof(Album);
                    navigationItem = navigationParameter as Track;
                    if (navigationItem != null)
                    {
                        navigationContainer = navigationItem.ContainingAlbum;
                    }
                }
            }
            else if (_pageState != null)
            {
                // If no navigationParameter but pageState available, modify UI according to pageState
                if (_pageState.ContainsKey("PageMode"))
                {
                    pageMode = Type.GetType((string)_pageState["PageMode"]);
                }

                if (_pageState.ContainsKey("AlbumScroll"))
                {
                    scroll = (double)_pageState["AlbumScroll"];
                }
            }

            PageMode             = pageMode;
            _pageState           = null;
            _navigationParameter = null;

            if (navigationContainer != null)
            {
                IsAlbumOverlayShown = true;

                // Delay scrolling after animation
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    CurrentSelection = navigationContainer;
                    albumGridView.ScrollIntoView(CurrentSelection);

                    if (navigationItem != null)
                    {
                        albumDetailListView.SelectedIndex = navigationContainer.IndexOf(navigationItem);
                        albumDetailListView.ScrollIntoView(albumDetailListView.SelectedItem);
                    }
                });
            }
            else if (scroll > double.Epsilon)             // Don't scroll if scroll is negative or less than Epsilon
            {
                // Delay scrolling after animation
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    FindVisualChild <ScrollViewer>(albumGridView).ScrollToHorizontalOffset(scroll);
                });
            }
        }
Example #3
0
        /// <summary>
        /// Replaces the entire track queue with a single song, queuing up the other items in the same track container.
        /// You should check the UserMutatedQueue property before performing a destructive replacement.
        /// </summary>
        /// <param name="t">The song.</param>
        /// <param name="a">The track container that holds the song.</param>
        public void ReplaceAllWithSong(Track t, ITrackContainer a)
        {
            Contract.Requires(t != null);
            Contract.Requires(a != null);
            Contract.Requires(a.TrackList != null);
            Contract.Requires(a.TrackList.Count != 0);

            _trackList.BatchChanges();

            Clear();

            var items = a.TrackList.AsParallel().AsOrdered().Select(x => x.UniqueTrack());
            _trackList.Enqueue(items);

            int trackOffset = Math.Max(0, a.IndexOf(t));
            _trackList.Dequeue(trackOffset);

            _trackList.FlushChanges();
        }