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; } }
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); }
private void HelperOnShutdown(object sender, EventArgs eventArgs) { CurrentQueue = null; NowPlayingSheetUtility.CloseNowPlaying(); IsPlayerActive = false; }
protected override void OnActivated(IActivatedEventArgs e) { base.OnActivated(e); StartApp(); if (e.Kind == ActivationKind.VoiceCommand) { var commandArgs = (VoiceCommandActivatedEventArgs)e; var speechRecognitionResult = commandArgs.Result; // If so, get the name of the voice command, the actual text spoken, and the value of Command/Navigate@Target. var voiceCommandName = speechRecognitionResult.RulePath[0]; switch (voiceCommandName) { case "Search": var term = speechRecognitionResult.SemanticInterpretation.Properties["term"].FirstOrDefault(); Navigator.GoTo <SearchPage, ZoomInTransition>(term); break; case "PlayEntry": var entryName = speechRecognitionResult.SemanticInterpretation.Properties["entry"].FirstOrDefault() .ToLower(); CollectionHelper.RequiresCollectionToLoad( async() => { var artist = Locator.CollectionService.Artists.FirstOrDefault( p => p.Name.ToLower().Contains(entryName)); List <Song> songs = null; if (artist != null) { songs = artist.Songs.OrderBy(p => p.Name).ToList(); } else { var album = Locator.CollectionService.Albums.FirstOrDefault( p => p.Name.ToLower().Contains(entryName)); if (album != null) { songs = album.Songs.OrderBy(p => p.Name).ToList(); } } if (songs != null) { await CollectionHelper.PlaySongsAsync(songs); } else { CurtainPrompt.ShowError("Coudln't find that album or artist in your collection."); } }); break; case "PlaySong": var songName = speechRecognitionResult.SemanticInterpretation.Properties["song"].FirstOrDefault().ToLower(); var artistName = speechRecognitionResult.SemanticInterpretation.Properties["entry"].FirstOrDefault() .ToLower(); if (artistName == "any artist") { artistName = string.Empty; } CollectionHelper.RequiresCollectionToLoad( async() => { var song = Locator.CollectionService.Songs.FirstOrDefault( p => p.Name.ToLower().Contains(songName) && (p.Artist.Name.ToLower().Contains(artistName) || p.ArtistName.ToLower().Contains(artistName))); if (song == null) { var album = Locator.CollectionService.Albums.FirstOrDefault( p => p.Name.ToLower().Contains(songName) && p.PrimaryArtist.Name.ToLower().Contains(artistName)); if (album == null) { CurtainPrompt.ShowError("Couldn't find that song or album in your collection."); } else { await CollectionHelper.PlaySongsAsync(album.Songs.OrderBy(p => p.Name).ToList()); } } else { var queue = Locator.CollectionService.CurrentPlaybackQueue.FirstOrDefault( p => p.SongId == song.Id); if (queue == null) { await CollectionHelper.PlaySongsAsync( song, Locator.CollectionService.Songs.OrderBy(p => p.Name).ToList()); } else { Locator.AudioPlayerHelper.PlaySong(queue); } } }); break; case "NowPlaying": CollectionHelper.RequiresCollectionToLoad( () => { if (Locator.Player.IsPlayerActive) { NowPlayingSheetUtility.OpenNowPlaying(); } else { CurtainPrompt.ShowError("Nothing playing right now."); } }); break; } } else { var continuationEventArgs = e as IContinuationActivatedEventArgs; if (continuationEventArgs != null) { _continuationManager.Continue(continuationEventArgs); } } }