private async void ConnectToLastFM_Click(object sender, RoutedEventArgs e)
        {
            LastFMScrobbler lastFm = new LastFMScrobbler(App.ApiKeyLastFm, "bd9ad107438d9107296ef799703d478e");

            string pseudo = (string)ApplicationSettingsHelper.ReadSettingsValue("LastFmUserName");
            string pd     = (string)ApplicationSettingsHelper.ReadSettingsValue("LastFmPassword");

            if (string.IsNullOrEmpty(pseudo) || string.IsNullOrEmpty(pd))
            {
                return;
            }
            ErrorConnectLastFmTextBox.Text       = Strings.Connecting;
            ErrorConnectLastFmTextBox.Visibility = Visibility.Visible;
            ErrorConnectLastFmTextBox.Foreground = new SolidColorBrush(Colors.Gray);
            var success = await lastFm.ConnectOperation(pseudo, pd);

            if (success)
            {
                ErrorConnectLastFmTextBox.Text       = "";
                ErrorConnectLastFmTextBox.Visibility = Visibility.Collapsed;
                Locator.SettingsVM.LastFmIsConnected = true;
            }
            else
            {
                ErrorConnectLastFmTextBox.Foreground = new SolidColorBrush(Colors.Red);
                ErrorConnectLastFmTextBox.Text       = Strings.CheckCredentials;
                Locator.SettingsVM.LastFmIsConnected = false;
            }
        }
Exemple #2
0
        public async Task Initialize()
        {
#if WINDOWS_APP
            App.Dispatcher?.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                MusicLibraryId = KnownLibraryId.Music;
                VideoLibraryId = KnownLibraryId.Videos;

                AddFolderToLibrary           = new AddFolderToLibrary();
                RemoveFolderFromMusicLibrary = new RemoveFolderFromMusicLibrary();
                RemoveFolderFromVideoLibrary = new RemoveFolderFromVideoLibrary();

                var notificationOnNewSong = ApplicationSettingsHelper.ReadSettingsValue("NotificationOnNewSong");
                NotificationOnNewSong     = notificationOnNewSong != null && (bool)notificationOnNewSong;

                var notificationOnNewSongForeground = ApplicationSettingsHelper.ReadSettingsValue("NotificationOnNewSongForeground");
                NotificationOnNewSongForeground     = notificationOnNewSongForeground != null && (bool)notificationOnNewSongForeground;
                var sidebar = ApplicationSettingsHelper.ReadSettingsValue("IsSidebarAlwaysMinimized");
                if (sidebar != null)
                {
                    IsSidebarAlwaysMinimized = (bool)sidebar;
                }

                var continuePlaybackInBackground = ApplicationSettingsHelper.ReadSettingsValue("ContinueVideoPlaybackInBackground");
                if (continuePlaybackInBackground != null)
                {
                    ContinueVideoPlaybackInBackground = (bool)continuePlaybackInBackground;
                }
                await GetLibrariesFolders();
            });
#endif
        }
Exemple #3
0
        private void SetTimer()
        {
            var  t  = ApplicationSettingsHelper.ReadSettingsValue(AppConstants.TimerTime);
            long tt = 0;

            if (t != null)
            {
                tt = (long)t;
            }

            TimeSpan currentTime      = TimeSpan.FromHours(DateTime.Now.Hour) + TimeSpan.FromMinutes(DateTime.Now.Minute) + TimeSpan.FromSeconds(DateTime.Now.Second);
            long     currentTimeTicks = currentTime.Ticks;

            TimeSpan delay = TimeSpan.FromTicks(tt - currentTimeTicks);

            if (delay > TimeSpan.Zero)
            {
                if (timerIsSet)
                {
                    TimerCancel();
                }
                timer      = ThreadPoolTimer.CreateTimer(new TimerElapsedHandler(TimerCallback), delay);
                timerIsSet = true;
            }
        }
Exemple #4
0
 void Initialize()
 {
     if (ApplicationSettingsHelper.ReadSettingsValue("ContinueVideoPlaybackInBackground") == null)
     {
         ApplicationSettingsHelper.SaveSettingsValue("ContinueVideoPlaybackInBackground", true);
     }
 }
Exemple #5
0
        public static void EnableBGImage()
        {
            //#80161616 = 128,22,22,22
            //#64161616 = 100,22,22,22
            //((SolidColorBrush)App.Current.Resources["UserListFontColor"]).Color = Windows.UI.Colors.White;
            string path = ApplicationSettingsHelper.ReadSettingsValue(AppConstants.BackgroundImagePath) as string;

            if (path != null && path != "")
            {
                ((ImageBrush)App.Current.Resources["BgImage"]).ImageSource = new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute));
                Windows.UI.Color color = Windows.UI.Color.FromArgb(128, 22, 22, 22);
                ((SolidColorBrush)App.Current.Resources["TransparentBGImageColor"]).Color = color;
                color = Windows.UI.Color.FromArgb(100, 22, 22, 22);
                ((SolidColorBrush)App.Current.Resources["TransparentMainPageBGImageColor"]).Color = color;
            }
            else
            {
            }

            if (App.Current.RequestedTheme == ApplicationTheme.Light)
            {
                App.Current.Resources["UserListFontColor"] = new SolidColorBrush(Windows.UI.Colors.White);
            }
            ChangeAlbumViewTransparency();
        }
Exemple #6
0
        async Task Initialize()
        {
            var accounts = accountDataRepository?.GetAccounts();

            if (accounts != null && accounts.Any())
            {
                Accounts = accounts;
                if (accounts.Count == 1)
                {
                    CurrentAccount = accounts[0];
#warning "Optimistic: any account/cookies is supposed valid, proper implementation needed (cookies timeout check)"
                    await ThreadUI.Invoke(() =>
                    {
                        Loc.NavigationService.Navigate(View.Connect);
                        Loc.Main.AccountManager.CurrentAccount.ConnectionErrorStatus = "Connecting";
                        Loc.Main.AccountManager.CurrentAccount.IsConnecting          = true;
                    });

                    bool success = await CurrentAccount.BeginAuthentication(false);

                    if (success)
                    {
                        await ThreadUI.Invoke(() =>
                        {
                            Loc.Main.AccountManager.CurrentAccount.IsConnected = false;
                            Loc.NavigationService.Navigate(View.Main);
                        });
                    }
                    else
                    {
                        Debug.WriteLine("Login failed");
                    }
                }
                else
                {
                    // Handle selection of one of the multi accounts
                }
            }
            else
            {
                // navigate to connectpage
                await ThreadUI.Invoke(() =>
                {
                    CurrentAccount = new Account();
                    Loc.NavigationService.Navigate(View.Connect);
                    // Trying to detect login and password stored in RoamingSettings
                    if (ApplicationSettingsHelper.Contains(nameof(CurrentAccount.Pseudo), false) && ApplicationSettingsHelper.Contains(nameof(CurrentAccount.Password), false))
                    {
                        ToastHelper.Simple("Connexion automatique ...");
                        var pseudo              = ApplicationSettingsHelper.ReadSettingsValue(nameof(CurrentAccount.Pseudo), false).ToString();
                        var password            = ApplicationSettingsHelper.ReadSettingsValue(nameof(CurrentAccount.Password), false).ToString();
                        CurrentAccount.Pseudo   = pseudo;
                        CurrentAccount.Password = password;
                        ConnectCommand.Execute(null);
                    }
                });
            }
        }
Exemple #7
0
 private void ScrobbleNowPlaying()
 {
     if ((bool)ApplicationSettingsHelper.ReadSettingsValue(AppConstants.LfmSendNP))
     {
         string artist = playlist.GetCurrentSong().Artist;
         string track  = playlist.GetCurrentSong().Title;
         SendNowPlayingScrobble(artist, track);
     }
 }
Exemple #8
0
        public static Languages GetSelectedLanguage()
        {
            var language = ApplicationSettingsHelper.ReadSettingsValue("Languages", false);

            if (language == null)
            {
                return(Languages.English);
            }
            return((Languages)language);
        }
Exemple #9
0
        private async Task RestorePlaylist()
        {
            try
            {
                var playlist = await BackgroundTrackRepository.LoadPlaylist();

                if (!playlist.Any())
                {
                    return;
                }

                var trackIds         = playlist.Select(node => node.TrackId);
                var restoredplaylist = new SmartCollection <IMediaItem>();
                foreach (int trackId in trackIds)
                {
                    var trackItem = await Locator.MediaLibrary.LoadTrackById(trackId);

                    if (trackItem != null)
                    {
                        restoredplaylist.Add(trackItem);
                    }
                }

                if (!ApplicationSettingsHelper.Contains(nameof(CurrentMedia)))
                {
                    return;
                }
                var index = (int)ApplicationSettingsHelper.ReadSettingsValue(nameof(CurrentMedia));
                if (restoredplaylist.Any())
                {
                    if (index == -1)
                    {
                        // Background Audio was terminated
                        // We need to reset the playlist, or set the current track 0.
                        ApplicationSettingsHelper.SaveSettingsValue(nameof(CurrentMedia), 0);
                        index = 0;
                    }
                    SetCurrentMediaPosition(index);
                }

                if (CurrentMedia >= restoredplaylist.Count || CurrentMedia == -1)
                {
                    CurrentMedia = 0;
                }

                if (restoredplaylist.Any())
                {
                    await SetPlaylist(restoredplaylist, true, false, restoredplaylist[CurrentMedia]);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Failed to restore the playlist");
            }
        }
Exemple #10
0
 private LastFmManager()
 {
     //Username = "******";
     //Password = "******";
     Username   = (ApplicationSettingsHelper.ReadSettingsValue(AppConstants.LfmLogin) ?? String.Empty).ToString();
     Password   = (ApplicationSettingsHelper.ReadSettingsValue(AppConstants.LfmPassword) ?? String.Empty).ToString();
     SessionKey = (ApplicationSettingsHelper.ReadSettingsValue(AppConstants.LfmSessionKey) ?? String.Empty).ToString();
     if (AreCredentialsSet())
     {
         SetSessionAndSendCached();
     }
 }
        private Uri GetCurrentTrackId()
        {
            object value = ApplicationSettingsHelper.ReadSettingsValue(ApplicationSettingsConstants.TrackId);

            if (value != null)
            {
                return(new Uri((String)value));
            }
            else
            {
                return(null);
            }
        }
Exemple #12
0
 private void StopSongEvent()
 {
     UpdateSongStatistics();
     if (ApplicationSettingsHelper.ReadSettingsValue(AppConstants.LfmLogin).ToString() != "" && BackgroundMediaPlayer.Current.NaturalDuration != TimeSpan.Zero)
     {
         System.Diagnostics.Debug.WriteLine("scrobble");
         ScrobbleTrack();
     }
     else
     {
         System.Diagnostics.Debug.WriteLine("no scrobble");
     }
 }
Exemple #13
0
        private bool FirstRun()
        {
            object o = ApplicationSettingsHelper.ReadSettingsValue(AppConstants.FirstRun);

            if (o == null)
            {
                ApplicationSettingsHelper.SaveSettingsValue(AppConstants.FirstRun, false);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #14
0
 internal void DeleteCurrentAccount()
 {
     if (CurrentAccount == null)
     {
         return;
     }
     accountDataRepository?.Delete(CurrentAccount);
     if (ApplicationSettingsHelper.Contains(nameof(CurrentAccount.Pseudo), false) &&
         ApplicationSettingsHelper.ReadSettingsValue(nameof(CurrentAccount.Pseudo), false).ToString() == CurrentAccount.Pseudo)
     {
         ApplicationSettingsHelper.ReadResetSettingsValue(nameof(CurrentAccount.Pseudo), false);
         ApplicationSettingsHelper.ReadResetSettingsValue(nameof(CurrentAccount.Password), false);
     }
     CurrentAccount = null;
 }
Exemple #15
0
        public static ApplicationTheme GetApplicationTheme()
        {
            var appTheme = ApplicationSettingsHelper.ReadSettingsValue(nameof(ApplicationTheme), false);
            ApplicationTheme applicationTheme;

            if (appTheme == null)
            {
                applicationTheme = App.Current.RequestedTheme;
            }
            else
            {
                applicationTheme = (ApplicationTheme)appTheme;
            }
            return(applicationTheme);
        }
Exemple #16
0
        private async void SetCover()
        {
            bool        isBGSet       = (bool)ApplicationSettingsHelper.ReadSettingsValue(AppConstants.IsBGImageSet);
            bool        isBGCover     = (bool)ApplicationSettingsHelper.ReadSettingsValue(AppConstants.ShowCoverAsBackground);
            BitmapImage originalCover = await Library.Current.GetOriginalCover(songs.FirstOrDefault().Path, false);

            if (isBGSet)
            {
                string path = ApplicationSettingsHelper.ReadSettingsValue(NextPlayerDataLayer.Constants.AppConstants.BackgroundImagePath) as string;
                if (path != null && path != "")
                {
                    BackgroundImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute));
                }
                if (isBGCover)
                {
                    if (originalCover.PixelHeight > 0)
                    {
                        BackgroundImage = originalCover;
                    }
                }
            }
            else
            {
                BackgroundImage = new BitmapImage();
                if (isBGCover)
                {
                    if (originalCover.PixelHeight > 0)
                    {
                        BackgroundImage = originalCover;
                    }
                }
            }
            if (originalCover.PixelHeight > 0)
            {
                Cover = originalCover;
            }
            else
            {
                Cover = await Library.Current.GetDefaultCover(false);

                if (!isBGSet)
                {
                    noBGForThisView = true;
                    ((SolidColorBrush)App.Current.Resources["TransparentAlbumInfoColor"]).Color    = Windows.UI.Color.FromArgb(0, 0, 0, 0);
                    ((SolidColorBrush)App.Current.Resources["TransparentAlbumBGImageColor"]).Color = Windows.UI.Color.FromArgb(0, 0, 0, 0);
                }
            }
        }
Exemple #17
0
        public static void ChangeAlbumViewTransparency()
        {
            bool cover = (bool)ApplicationSettingsHelper.ReadSettingsValue(AppConstants.ShowCoverAsBackground);
            bool image = (bool)ApplicationSettingsHelper.ReadSettingsValue(AppConstants.IsBGImageSet);

            if (cover || image)
            {
                ((SolidColorBrush)App.Current.Resources["TransparentAlbumInfoColor"]).Color    = Windows.UI.Color.FromArgb(100, 22, 22, 22);
                ((SolidColorBrush)App.Current.Resources["TransparentAlbumBGImageColor"]).Color = Windows.UI.Color.FromArgb(128, 22, 22, 22);
            }
            else
            {
                ((SolidColorBrush)App.Current.Resources["TransparentAlbumInfoColor"]).Color    = Windows.UI.Color.FromArgb(0, 0, 0, 0);
                ((SolidColorBrush)App.Current.Resources["TransparentAlbumBGImageColor"]).Color = Windows.UI.Color.FromArgb(0, 0, 0, 0);
            }
        }
Exemple #18
0
        private bool NeedsToDrop()
        {
            Package        thisPackage = Package.Current;
            PackageVersion version     = thisPackage.Id.Version;

            if (ApplicationSettingsHelper.Contains(Strings.DatabaseVersion) && (int)ApplicationSettingsHelper.ReadSettingsValue(Strings.DatabaseVersion) == Numbers.DbVersion)
            {
                LogHelper.Log("DB does not need to be dropped.");
                return(false);
            }
            else
            {
                LogHelper.Log("DB needs to be dropped.");
                ApplicationSettingsHelper.SaveSettingsValue(Strings.DatabaseVersion, Numbers.DbVersion);
                return(true);
            }
        }
Exemple #19
0
        public async Task ResumePlayback()
        {
            if (mediaPlayer.CurrentState == MediaPlayerState.Playing || mediaPlayer.CurrentState == MediaPlayerState.Paused)
            {
                SendPosition();
                return;
            }
            paused  = false;
            isFirst = false;
            object position = ApplicationSettingsHelper.ReadSettingsValue(AppConstants.Position);

            if (position != null)
            {
                startPosition = TimeSpan.Parse(position.ToString());
            }
            await LoadFile(playlist.GetCurrentSong().Path);
        }
Exemple #20
0
        private async void OnPlaylistEndReached()
        {
            var isAppCurrentlyBackgrounded = ApplicationSettingsHelper.ReadSettingsValue("AppBackgrounded") as bool?;

            if (isAppCurrentlyBackgrounded.HasValue && isAppCurrentlyBackgrounded.Value)
            {
                return;
            }

            await DispatchHelper.InvokeInUIThread(CoreDispatcherPriority.Low, () =>
            {
                if (PlaybackService.PlayingType == PlayingType.Video)
                {
                    App.RootPage.StopCompositionAnimationOnSwapChain();
                }
                Locator.NavigationService.GoBack_Default();
            });
        }
Exemple #21
0
        private void UpdateDB()
        {
            //var settings = ApplicationData.Current.LocalSettings;

            //if (!settings.Values.ContainsKey(AppConstants.DBVersion))
            //{
            //    DatabaseManager.UpdateDBToVersion2();
            //    settings.Values.Add(AppConstants.DBVersion, "2");
            //}
            int v = (int)ApplicationSettingsHelper.ReadSettingsValue(AppConstants.DBVersion);

            if (v == 2)
            {
                ApplicationSettingsHelper.SaveSettingsValue(AppConstants.DBVersion, 3);
                ApplicationSettingsHelper.ReadResetSettingsValue("savelaterlyrics");
                DatabaseManager.UpdateDBToVersion3();
            }
        }
Exemple #22
0
        public async Task UpdateTrackFromMF()
        {
            await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
#if WINDOWS_PHONE_APP
                // TODO : this shouldn't be here
                Locator.MediaPlaybackViewModel.OnLengthChanged((long)BackgroundMediaPlayer.Current.NaturalDuration.TotalMilliseconds);
#endif
                if (!ApplicationSettingsHelper.Contains(BackgroundAudioConstants.CurrentTrack))
                {
                    return;
                }
                int index = (int)ApplicationSettingsHelper.ReadSettingsValue(BackgroundAudioConstants.CurrentTrack);
                Locator.MediaPlaybackViewModel.TrackCollection.CurrentTrack = index;
                await SetCurrentArtist();
                await SetCurrentAlbum();
                await UpdatePlayingUI();
            });
        }
        private void RBTheme_Checked(object sender, RoutedEventArgs e)
        {
            RadioButton rb = sender as RadioButton;

            if (rb.Name == "RBDark")
            {
                ApplicationSettingsHelper.SaveSettingsValue(AppConstants.AppTheme, AppThemeEnum.Dark.ToString());
                TrackEvent("Theme changed Dark");
            }
            else if (rb.Name == "RBLight")
            {
                ApplicationSettingsHelper.SaveSettingsValue(AppConstants.AppTheme, AppThemeEnum.Light.ToString());
                if ((bool)ApplicationSettingsHelper.ReadSettingsValue(AppConstants.IsBGImageSet))
                {
                    App.Current.Resources["UserListFontColor"] = new SolidColorBrush(Windows.UI.Colors.White);
                }
                TrackEvent("Theme changed Light");
            }
        }
        private void SendMessage(string s)
        {
            object value = ApplicationSettingsHelper.ReadSettingsValue(AppConstants.BackgroundTaskState);

            if (value == null)
            {
                return;
            }
            else
            {
                bool run = ((String)value).Equals(AppConstants.BackgroundTaskRunning);
                if (run)
                {
                    var msg = new ValueSet();
                    msg.Add(s, "");
                    BackgroundMediaPlayer.SendMessageToBackground(msg);
                }
            }
        }
Exemple #25
0
        public static void ChangeMainPageButtonsBackground()
        {
            bool isImageSet    = (bool)ApplicationSettingsHelper.ReadSettingsValue(AppConstants.IsBGImageSet);
            bool isPhoneAccent = (bool)ApplicationSettingsHelper.ReadSettingsValue(AppConstants.IsPhoneAccentSet);

            Windows.UI.Color color;
            if (isImageSet)
            {
                byte a = byte.Parse("80", System.Globalization.NumberStyles.HexNumber);
                if (isPhoneAccent)
                {
                    color   = ((SolidColorBrush)Application.Current.Resources["PhoneAccentBrush"]).Color;
                    color.A = a;
                }
                else
                {
                    string hexColor = ApplicationSettingsHelper.ReadSettingsValue(AppConstants.AppAccent) as string;
                    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);
                    color = Windows.UI.Color.FromArgb(a, r, g, b);
                }
                ((SolidColorBrush)App.Current.Resources["MainPageButtonsBackground"]).Color = color;
            }
            else
            {
                if (isPhoneAccent)
                {
                    ((SolidColorBrush)App.Current.Resources["MainPageButtonsBackground"]).Color = ((SolidColorBrush)Application.Current.Resources["PhoneAccentBrush"]).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);
                    color = Windows.UI.Color.FromArgb(a, r, g, b);
                    ((SolidColorBrush)App.Current.Resources["MainPageButtonsBackground"]).Color = color;
                }
            }
        }
Exemple #26
0
        public async Task UpdateWindows8UI()
        {
            // Setting the info for windows 8 controls
            string artistName = CurrentTrack?.ArtistName ?? Strings.UnknownArtist;
            string albumName  = CurrentTrack?.AlbumName ?? Strings.UnknownAlbum;
            string trackName  = CurrentTrack?.Name ?? Strings.UnknownTrack;
            var    picture    = Locator.MusicPlayerVM.CurrentAlbum != null ? Locator.MusicPlayerVM.CurrentAlbum.AlbumCoverUri : null;

            await Locator.MediaPlaybackViewModel.SetMediaTransportControlsInfo(artistName, albumName, trackName, picture);

            var notificationOnNewSong = ApplicationSettingsHelper.ReadSettingsValue("NotificationOnNewSong");

            if (notificationOnNewSong != null && (bool)notificationOnNewSong)
            {
                var notificationOnNewSongForeground = ApplicationSettingsHelper.ReadSettingsValue("NotificationOnNewSongForeground");
                if (Locator.MainVM.IsBackground || (notificationOnNewSongForeground != null && (bool)notificationOnNewSongForeground))
                {
                    ToastHelper.ToastImageAndText04(trackName, albumName, artistName, (Locator.MusicPlayerVM.CurrentAlbum == null) ? null : Locator.MusicPlayerVM.CurrentAlbum.AlbumCoverUri ?? null);
                }
            }
        }
 private void ColorAccent_Toggled(object sender, RoutedEventArgs e)
 {
     if (((ToggleSwitch)sender).IsOn)
     {
         Windows.UI.Color color = ((SolidColorBrush)Application.Current.Resources["PhoneAccentBrush"]).Color;
         ((SolidColorBrush)App.Current.Resources["UserAccentBrush"]).Color = color;
         ApplicationSettingsHelper.SaveSettingsValue(AppConstants.IsPhoneAccentSet, true);
     }
     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;
         ApplicationSettingsHelper.SaveSettingsValue(AppConstants.IsPhoneAccentSet, false);
     }
     Helpers.StyleHelper.ChangeMainPageButtonsBackground();
 }
Exemple #28
0
        public async Task RestorePlaylist()
        {
            var playlist = Locator.MusicPlayerVM.BackgroundTrackRepository.LoadPlaylist();

            if (!playlist.Any())
            {
                return;
            }
            var trackIds = playlist.Select(node => node.Id);

            Playlist = new ObservableCollection <IVLCMedia>();
            foreach (int trackId in trackIds)
            {
                var trackItem = await Locator.MusicLibraryVM._trackDatabase.LoadTrack(trackId);

                Playlist.Add(trackItem);
            }
            IsRunning = true;

            var currentTrack = ApplicationSettingsHelper.ReadSettingsValue(BackgroundAudioConstants.CurrentTrack);

            if (currentTrack != null)
            {
                CurrentTrack = (int)currentTrack;
                if ((int)currentTrack == -1)
                {
                    // Background Audio was terminated
                    // We need to reset the playlist, or set the current track 0.
                    ApplicationSettingsHelper.SaveSettingsValue(BackgroundAudioConstants.CurrentTrack, 0);
                    CurrentTrack = 0;
                }
            }
            await Locator.MusicPlayerVM.UpdateTrackFromMF();

            App.BackgroundAudioHelper.RestorePlaylist();
            if (Locator.MusicPlayerVM.CurrentTrack != null)
            {
                await Locator.MediaPlaybackViewModel.SetMedia(Locator.MusicPlayerVM.CurrentTrack, false, false);
            }
        }
Exemple #29
0
 private void ApplicationState_Activated(object sender, WindowActivatedEventArgs e)
 {
     if (e.WindowActivationState == CoreWindowActivationState.Deactivated)
     {
         IsBackground = true;
         if (Locator.MediaPlaybackViewModel.CurrentMedia == null)
         {
             return;
         }
         if (!Locator.MediaPlaybackViewModel.IsPlaying)
         {
             return;
         }
         // If we're playing a video, just pause.
         if (Locator.MediaPlaybackViewModel.PlayingType == PlayingType.Video)
         {
             // TODO: Route Video Player calls through Media Service
             if (!(bool)ApplicationSettingsHelper.ReadSettingsValue("ContinueVideoPlaybackInBackground"))
             {
                 Locator.MediaPlaybackViewModel._mediaService.Pause();
             }
         }
     }
     else
     {
         IsBackground = false;
         if (Locator.MediaPlaybackViewModel.CurrentMedia == null)
         {
             return;
         }
         if (Locator.MediaPlaybackViewModel.PlayingType != PlayingType.Video)
         {
             return;
         }
         if (Locator.MediaPlaybackViewModel.MediaState == MediaState.Paused)
         {
             Locator.MediaPlaybackViewModel._mediaService.Pause();
         }
     }
 }
Exemple #30
0
        public void Restore()
        {
            if (!ApplicationSettingsHelper.Contains(nameof(Index)))
            {
                return;
            }

            var playlist = BackgroundTrackRepository.LoadPlaylist();

            if (!playlist.Any())
            {
                return;
            }

            var trackIds         = playlist.Select(node => node.TrackId);
            var restoredplaylist = new SmartCollection <IMediaItem>();

            foreach (int trackId in trackIds)
            {
                var trackItem = Locator.MediaLibrary.LoadTrackById(trackId);
                if (trackItem != null)
                {
                    restoredplaylist.Add(trackItem);
                }
            }

            if (restoredplaylist.Count == 0)
            {
                return;
            }
            clear();
            _playlist = restoredplaylist;
            OnPlaylistChanged?.Invoke();
            _index = (int)ApplicationSettingsHelper.ReadSettingsValue(nameof(Index));
            OnCurrentMediaChanged?.Invoke(_playlist[_index], true);
        }