public NowPlayingSong PreviousSong() { NowPlayingSong song; isSongRepeated = false; if (shuffle) { if (previousIndex == -1) { currentIndex = GetRandomIndex(); } else { currentIndex = previousIndex; previousIndex = -1; } } else { if (IsFirst()) { currentIndex = playlist.Count - 1; } else { currentIndex--; } } ApplicationSettingsHelper.SaveSongIndex(currentIndex); song = GetCurrentSong(); return(song); }
public NowPlayingSong ChangeSong(int index) { previousIndex = currentIndex; currentIndex = index; isSongRepeated = false; ApplicationSettingsHelper.SaveSongIndex(currentIndex); return(GetCurrentSong()); }
public void PlayNow(PlaylistItem playlist) { ObservableCollection <SongItem> songList = new ObservableCollection <SongItem>(); if (playlist.IsSmart) { songList = DatabaseManager.GetSongItemsFromSmartPlaylist(playlist.Id); } else { songList = DatabaseManager.GetSongItemsFromPlainPlaylist(playlist.Id); } Library.Current.SetNowPlayingList(songList); ApplicationSettingsHelper.SaveSongIndex(0); navigationService.NavigateTo(ViewNames.NowPlayingView, "start"); }
public void CheckNPAfterUpdate(IEnumerable <int> toAvailable) { List <SongItem> list = new List <SongItem>(); foreach (var song in nowPlayingList) { if (toAvailable.Contains(song.SongId)) { list.Add(song); } } if (list.Count <= ApplicationSettingsHelper.ReadSongIndex()) { ApplicationSettingsHelper.SaveSongIndex(list.Count - 1); } SetNowPlayingList(list); }
void App_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Logger.SaveInSettings(e.Exception.ToString() + "\nMessage:\n" + e.Message); if (e != null) { Exception exception = e.Exception; if (exception is NullReferenceException && exception.ToString().ToUpper().Contains("SOMA")) { Debug.WriteLine("Handled Smaato null reference exception {0}", exception); e.Handled = true; return; } else if (exception.ToString().Contains("AdDuplex")) { e.Handled = true; return; } } ApplicationSettingsHelper.ReadResetSettingsValue(AppConstants.MediaScan); int i = ApplicationSettingsHelper.ReadSongIndex(); int npc = Library.Current.NowPlayingList.Count; if (i >= 0 && npc > 0 && npc > i) { ApplicationSettingsHelper.SaveSongIndex(i); } else { ApplicationSettingsHelper.SaveSongIndex(-1); if (npc >= 0) { ApplicationSettingsHelper.SaveSongIndex(0); } } DiagnosticHelper.TrackTrace("Unhandled Exception " + e.Exception.ToString() + "\n" + e.Message, Microsoft.HockeyApp.SeverityLevel.Error); }
private void Sort(Func <SongItem, object> selector) { int id = -1; if (isNowPlaying) { if (playlist.Count == 0) { return; } id = playlist.ElementAt(index).SongId; } if (ascending) { Playlist = new ObservableCollection <SongItem>(playlist.OrderBy(selector)); } else { Playlist = new ObservableCollection <SongItem>(playlist.OrderByDescending(selector)); } if (isNowPlaying) { int i = 0; foreach (var item in playlist) { if (item.SongId == id) { break; } i++; } index = i; ApplicationSettingsHelper.SaveSongIndex(index); Library.Current.SetNowPlayingList(Playlist); NPChange.SendMessageNPSorted(); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used when the application is launched to open a specific file, to display /// search results, and so forth. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { this.DebugSettings.EnableFrameRateCounter = true; } #endif var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView(); string theme = ApplicationSettingsHelper.ReadSettingsValue(AppConstants.AppTheme) as string; if (theme.Equals(AppThemeEnum.Dark.ToString())) { statusBar.BackgroundColor = Windows.UI.Colors.Black; statusBar.ForegroundColor = Windows.UI.Colors.White; } else if (theme.Equals(AppThemeEnum.Light.ToString())) { statusBar.BackgroundColor = Windows.UI.Colors.White; statusBar.ForegroundColor = Windows.UI.Colors.Black; } bool isPhoneAccent = (bool)ApplicationSettingsHelper.ReadSettingsValue(AppConstants.IsPhoneAccentSet); try { if (isPhoneAccent) { Windows.UI.Color color = ((SolidColorBrush)Application.Current.Resources["PhoneAccentBrush"]).Color; ((SolidColorBrush)App.Current.Resources["UserAccentBrush"]).Color = color; } else { string hexColor = ApplicationSettingsHelper.ReadSettingsValue(AppConstants.AppAccent) as string; byte a = byte.Parse(hexColor.Substring(1, 2), System.Globalization.NumberStyles.HexNumber); byte r = byte.Parse(hexColor.Substring(3, 2), System.Globalization.NumberStyles.HexNumber); byte g = byte.Parse(hexColor.Substring(5, 2), System.Globalization.NumberStyles.HexNumber); byte b = byte.Parse(hexColor.Substring(7, 2), System.Globalization.NumberStyles.HexNumber); Windows.UI.Color color = Windows.UI.Color.FromArgb(a, r, g, b); ((SolidColorBrush)App.Current.Resources["UserAccentBrush"]).Color = color; } } catch (Exception ex) { DiagnosticHelper.TrackTrace("User accent set" + Environment.NewLine + ex.Message, SeverityLevel.Information); } if ((bool)ApplicationSettingsHelper.ReadSettingsValue(AppConstants.IsBGImageSet)) { Helpers.StyleHelper.EnableBGImage(); } Helpers.StyleHelper.ChangeMainPageButtonsBackground(); Helpers.StyleHelper.ChangeAlbumViewTransparency(); ApplicationSettingsHelper.SaveSettingsValue(AppConstants.AppState, AppConstants.ForegroundAppActive); Frame rootFrame = Window.Current.Content as Frame; bool fromTile = false; if (e.TileId.Contains(AppConstants.TileId)) { string[] s = ParamConvert.ToStringArray(e.Arguments); if (s[0].Equals("album")) { var a = DatabaseManager.GetSongItemsFromAlbum(s[1], s[2]); Library.Current.SetNowPlayingList(a); } else if (s[0].Equals("playlist")) { if (s[2].Equals(true.ToString())) { Library.Current.SetNowPlayingList(DatabaseManager.GetSongItemsFromSmartPlaylist(Int32.Parse(s[1]))); } else { Library.Current.SetNowPlayingList(DatabaseManager.GetSongItemsFromPlainPlaylist(Int32.Parse(s[1]))); } } else if (s[0].Equals("artist")) { Library.Current.SetNowPlayingList(DatabaseManager.GetSongItemsFromArtist(s[1])); } else if (s[0].Equals("genre")) { Library.Current.SetNowPlayingList(DatabaseManager.GetSongItemsFromGenre(s[1])); } else if (s[0].Equals("folder")) { Library.Current.SetNowPlayingList(DatabaseManager.GetSongItemsFromFolder(s[1])); } ApplicationSettingsHelper.SaveSongIndex(0); ApplicationSettingsHelper.SaveSettingsValue(AppConstants.TilePlay, true); rootFrame = null; fromTile = true; } // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); // Associate the frame with a SuspensionManager key. if (fromTile) { SuspensionManager.SessionState.Clear(); } SuspensionManager.RegisterFrame(rootFrame, "AppFrame"); // TODO: change this value to a cache size that is appropriate for your application rootFrame.CacheSize = 1; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Restore the saved session state only when appropriate. if (!fromTile) { try { //Logger.Save("resumed terminate app"); //Logger.SaveToFile(); ApplicationSettingsHelper.SaveSettingsValue(AppConstants.ResumePlayback, ""); await SuspensionManager.RestoreAsync(); } catch (SuspensionManagerException ex) { // Something went wrong restoring state. // Assume there is no state and continue. Logger.Save("App OnLaunched() SuspensionManagerException" + "\n" + ex.Message); Logger.SaveToFileBG(); } } } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // Removes the turnstile navigation for startup. if (rootFrame.ContentTransitions != null) { this.transitions = new TransitionCollection(); foreach (var c in rootFrame.ContentTransitions) { this.transitions.Add(c); } } rootFrame.ContentTransitions = null; rootFrame.Navigated += this.RootFrame_FirstNavigated; // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter if (!rootFrame.Navigate(typeof(View.MainPage), e.Arguments)) { throw new Exception("Failed to create initial page"); } } //rootFrame.Background = (ImageBrush)Resources["BgImage"]; // Ensure the current window is active Window.Current.Activate(); //SetDimensions(); DispatcherHelper.Initialize(); await HockeyClient.Current.SendCrashesAsync(true); }
//zwraca null, jesli nie ma nastepnego utworu do zagrania(np. jest koniec playlisty) public NowPlayingSong NextSong(bool userChoice) { NowPlayingSong song; bool stop = false; previousIndex = currentIndex; if (repeat == RepeatEnum.NoRepeat) { if (shuffle) { currentIndex = GetRandomIndex(); } else { if (IsLast()) { if (userChoice) { currentIndex = 0; } else { stop = true; } } else { currentIndex++; } } } if (repeat == RepeatEnum.RepeatOnce) { if (isSongRepeated) { isSongRepeated = false; if (shuffle) { currentIndex = GetRandomIndex(); } else { if (IsLast()) { if (userChoice) { currentIndex = 0; } else { stop = true; } } else { currentIndex++; } } } else { if (userChoice) { if (shuffle) { currentIndex = GetRandomIndex(); } else { if (IsLast()) { if (userChoice) { currentIndex = 0; } else { stop = true; } } else { currentIndex++; } } } else { isSongRepeated = true; } } } else if (repeat == RepeatEnum.RepeatPlaylist) { if (shuffle) { currentIndex = GetRandomIndex(); } else { if (isPlaylistRepeated) { if (IsLast()) { if (userChoice) { currentIndex = 0; } else { currentIndex = 0; //stop = true; } } else { currentIndex++; } } else { if (IsLast()) { currentIndex = 0; isPlaylistRepeated = true; } else { currentIndex++; } } } } if (stop) { return(null); } ApplicationSettingsHelper.SaveSongIndex(currentIndex); song = GetCurrentSong(); return(song); }