示例#1
0
        private void HelperOnTrackChanged(object sender, EventArgs eventArgs)
        {
            var playerInstance = _helper.SafeMediaPlayer;

            if (playerInstance == null)
            {
                return;
            }

            var state = _helper.SafePlayerState;

            if (state != MediaPlayerState.Closed && state != MediaPlayerState.Stopped)
            {
                if (CurrentQueue != null && CurrentQueue.Song != null)
                {
                    var lastPlayed = DateTime.Now - CurrentQueue.Song.LastPlayed;

                    if (lastPlayed.TotalSeconds > 30)
                    {
                        CurrentQueue.Song.PlayCount++;
                        CurrentQueue.Song.LastPlayed = DateTime.Now;
                    }
                }

                var currentId = _appSettingsHelper.Read <int>(PlayerConstants.CurrentTrack);
                var newQueue  = _service.PlaybackQueue.FirstOrDefault(p => p.Id == currentId);

                if (CurrentQueue != newQueue)
                {
                    IsLoading = true;
                    Position  = TimeSpan.Zero;

                    CurrentQueue = newQueue;

                    if (CurrentQueue != null && CurrentQueue.Song != null &&
                        CurrentQueue.Song.Duration.Ticks != Duration.Ticks)
                    {
                        CurrentQueue.Song.Duration = Duration;
                    }
                }
                IsPlayerActive = true;
            }
            else
            {
                NowPlayingSheetUtility.CloseNowPlaying();
                IsPlayerActive = false;
                CurrentQueue   = null;
            }

            Duration = playerInstance.NaturalDuration;
            if (Duration == TimeSpan.MinValue)
            {
                Duration = TimeSpan.Zero;
            }
        }
示例#2
0
 private void HelperOnShutdown(object sender, EventArgs eventArgs)
 {
     CurrentQueue = null;
     NowPlayingSheetUtility.CloseNowPlaying();
     IsPlayerActive = false;
 }
示例#3
0
        public void StartApp(string argument = "")
        {
            CreateRootFrame();

            var restore = Locator.AppSettingsHelper.Read <bool>("FactoryReset") ||
                          Locator.AppSettingsHelper.Read <bool>("Restore");

            if (RootFrame.Content == null)
            {
                Insights.Initialize("38cc9488b4e09fd2c316617d702838ca43a473d4");
                CollectionHelper.IdentifyXamarin();
                RootFrame.Navigated += RootFrame_FirstNavigated;

                // MainPage is always in rootFrame so we don't have to worry about restoring the navigation state on resume
                RootFrame.Navigate(typeof(RootPage), null);
            }

            if (argument.StartsWith("artists/"))
            {
                NowPlayingSheetUtility.CloseNowPlaying();

                if (Navigator.CurrentPage is CollectionArtistPage)
                {
                    Navigator.GoBack();
                }

                var id = int.Parse(argument.Replace("artists/", string.Empty));

                CollectionHelper.RequiresCollectionToLoad(
                    () =>
                {
                    if (Locator.CollectionService.Artists.FirstOrDefault(p => p.Id == id) != null)
                    {
                        Navigator.GoTo <CollectionArtistPage, ZoomInTransition>(id);
                    }
                });
            }
            else if (argument.StartsWith("albums/"))
            {
                NowPlayingSheetUtility.CloseNowPlaying();

                if (Navigator.CurrentPage is CollectionAlbumPage)
                {
                    Navigator.GoBack();
                }

                var id = int.Parse(argument.Replace("albums/", string.Empty));
                CollectionHelper.RequiresCollectionToLoad(
                    () =>
                {
                    if (Locator.CollectionService.Albums.FirstOrDefault(p => p.Id == id) != null)
                    {
                        Navigator.GoTo <CollectionAlbumPage, ZoomInTransition>(id);
                    }
                });
            }

            // Ensure the current window is active
            Window.Current.Activate();

            // ReSharper disable once CSharpWarnings::CS4014
            if (!restore)
            {
                BootAppServicesAsync();
            }

            var dataManager = DataTransferManager.GetForCurrentView();

            dataManager.DataRequested += DataTransferManagerOnDataRequested;

            if (Locator.AppVersionHelper.JustUpdated)
            {
                OnUpdate();
            }
            else if (Locator.AppVersionHelper.IsFirstRun)
            {
                Locator.AppSettingsHelper.WriteAsJson("LastRunVersion", Locator.AppVersionHelper.CurrentVersion);
            }

            OnVisibleBoundsChanged(null, null);
        }