Beispiel #1
0
        public static async Task LoadMusicFromJSON()
        {
            try
            {
                try
                {
                    App.GetForCurrentView().DisplayLoading(0, 0, 0, false);
                }
                catch { }
                StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;

                //StorageFile albumdictfile = await storageFolder.CreateFileAsync("albumdict.txt", Windows.Storage.CreationCollisionOption.OpenIfExists);
                StorageFile albumdictfile = await storageFolder.GetFileAsync("albumdict.txt");

                string albumdictjson = await FileIO.ReadTextAsync(albumdictfile);

                var albumdict = JsonConvert.DeserializeObject <ConcurrentDictionary <String, Album> >(albumdictjson);
                SongListStorage.AlbumDict = albumdict;

                StorageFile songdictfile = await storageFolder.GetFileAsync("songdict.txt");

                string songdictjson = await FileIO.ReadTextAsync(songdictfile);

                var songdict = JsonConvert.DeserializeObject <ConcurrentDictionary <String, Song> >(songdictjson);
                SongListStorage.SongDict = songdict;

                StorageFile artistdictfile = await storageFolder.GetFileAsync("artistdict.txt");

                string artistdictjson = await FileIO.ReadTextAsync(artistdictfile);

                var artistdict = JsonConvert.DeserializeObject <ConcurrentDictionary <string, Artist> >(artistdictjson);
                SongListStorage.ArtistDict = artistdict;

                Debug.WriteLine("Loaded music from JSON.");
                try
                {
                    App.GetForCurrentView().DisplayLoading(SongListStorage.SongDict.Count, 0, 0, true);
                }
                catch
                {
                }
            }
            catch (FileNotFoundException E)
            {
                Debug.WriteLine("Couldn't load music.");
                Debug.WriteLine(E.Message);
                await GetSongs(true);
            }
            catch (Newtonsoft.Json.JsonSerializationException E)
            {
                Debug.WriteLine("Couldn't load music.");
                Debug.WriteLine(E.Message);
                await GetSongs(true);
            }
            catch (Exception E)
            {
                Debug.WriteLine("Couldn't load music.");
                Debug.WriteLine(E.Message);
                await GetSongs(true);
            }
            if (!Windows.Storage.ApplicationData.Current.LocalSettings.Values.ContainsKey("ShowUnpinnedFlavours"))
            {
                Windows.Storage.ApplicationData.Current.LocalSettings.Values["ShowUnpinnedFlavours"] = true;
            }
            await SongListStorage.GetNowPlaying();

            await SongListStorage.GetPlaylistFolder();

            await SongListStorage.LoadFlavours();

            SongListStorage.LoadVolume();
            Media.Instance.VolChanged();
            await SongListStorage.UpdateAndOrderMusic();

            await Windows.System.Threading.ThreadPool.RunAsync(SongListStorage.PeriodicallySave, Windows.System.Threading.WorkItemPriority.High);


            //SongListStorage.GetSongList();
        }