예제 #1
0
        public async Task RemoveSong(int index)
        {
            if (SongListStorage.CurrentPlaceInPlaylist == index)
            {
                Playlist.MovePrevious();
            }

            Playlist.Items.RemoveAt(index);
            SongListStorage.PlaylistRepresentation.RemoveAt(index);
            int place = (int)Playlist.CurrentItemIndex;

            if (Playlist.CurrentItemIndex == 4294967295) //Magic number?? Perfectly totient.
            {
                SongListStorage.CurrentPlaceInPlaylist = 0;
            }
            else
            {
                SongListStorage.CurrentPlaceInPlaylist = place;
            }
            await SongListStorage.SaveNowPlaying();

            /*if (SongListStorage.PlaylistRepresentation.Count == 0)
             * {
             *  mediaPlayer.Source = new MediaPlaybackList();
             *  Currentart = DefaultArt;
             *  Currentartist = "";
             *  Currenttitle = "";
             * }*/
        }
예제 #2
0
        public async static Task <bool> SaveNowPlaying()
        {
            while (true)
            {
                try
                {
                    if (PlaylistRepresentation.Count > 0)
                    {
                        string        nowplayingstring = SongListStorage.NowPlayingToString();
                        StorageFolder storageFolder    = Windows.Storage.ApplicationData.Current.LocalFolder;
                        StorageFile   nowplayingfile   = await storageFolder.CreateFileAsync("nowplaying.txt", Windows.Storage.CreationCollisionOption.OpenIfExists);

                        //storageFolder.
                        await FileIO.WriteTextAsync(nowplayingfile, nowplayingstring);

                        SavePlace();
                    }

                    return(true);
                }
                catch (FileLoadException E)
                {
                    Debug.WriteLine("Couldn't save now playing.");
                    Debug.WriteLine(E.Message);
                }
                catch (IOException E)
                {
                    Debug.WriteLine("Couldn't save now playing.");
                    Debug.WriteLine(E.Message);
                }
            }
        }
예제 #3
0
        private async Task saveRichPresenceInfo()
        {
            //var storageFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync(@"Assets");
            //var f = new StorageFolder(new Uri("ms - appx:///Assets/discordrpc"));
            //Windows.Storage.ApplicationData.Current.
            //KnownFolders.MusicLibrary.CreateFileAsync
            var localfolder = Windows.Storage.ApplicationData.Current.LocalFolder;
            var file        = await localfolder.CreateFileAsync("RichPresenceInfo.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting);

            while (true)
            {
                await Task.Delay(500);

                //var musicLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Music);
                //musicLibrary.
                //Debug.WriteLine(musicLibrary.SaveFolder.Path);

                //var file = await KnownFolders.MusicLibrary.CreateFileAsync("RichPresenceInfo.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting);

                long timeleft = 0;
                var  song     = SongListStorage.GetCurrentSong();
                if (song != null)
                {
                    timeleft = song.Duration.Subtract(mediaPlayer.PlaybackSession.Position).Ticks;
                }

                await FileIO.WriteTextAsync(file, currentartist + "\n" + currenttitle + "\n" + timeleft + "\n" + DateTime.UtcNow.Ticks + "\n" + mediaPlayer.PlaybackSession.PlaybackState);

                Debug.WriteLine("Hopefully wrote to file at " + DateTime.Now.ToString());
            }
        }
예제 #4
0
        private async void PickPlayListFolderButton_Click(object sender, RoutedEventArgs e)
        {
            var folderPicker = new Windows.Storage.Pickers.FolderPicker();

            folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
            folderPicker.FileTypeFilter.Add("*");

            Windows.Storage.StorageFolder folder = await folderPicker.PickSingleFolderAsync();

            if (folder != null)
            {
                // Application now has read/write access to all contents in the picked folder
                // (including other sub-folder contents)
                Windows.Storage.AccessCache.StorageApplicationPermissions.
                FutureAccessList.AddOrReplace("PlaylistFolder", folder);
                ChosenFolderText.Text        = "Picked folder: " + folder.Name;
                SongListStorage.PlaylistDict = new ConcurrentDictionary <long, Playlist>();
                SongListStorage.LoadFlavours();
                SongListStorage.PlayListFolder = folder;
            }
            else
            {
                ChosenFolderText.Text = "No Folder Found.";
            }
        }
예제 #5
0
 public async Task AddToPlaylist()
 {
     foreach (String songid in Songids)
     {
         await Media.Instance.AddSong(songid, false);
     }
     App.GetForCurrentView().NotificationMessage("Added " + Artist + " - " + Name + " to now playing.");
     await SongListStorage.SaveNowPlaying();
 }
예제 #6
0
 private async void Playlist_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
     {
         if (!lastremovewasdel)
         {
             oldmoveindex = e.OldStartingIndex;
         }
         lastremovewasdel = false;
     }
     if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) //Bugged when adding songs
     {
         int newmoveindex = e.NewStartingIndex;
         if (oldmoveindex != -1)
         {
             try
             {
                 var currenttime = Media.Instance.GetSongTime();
                 int place       = SongListStorage.CurrentPlaceInPlaylist;
                 if (oldmoveindex == place)
                 {
                     place = newmoveindex;
                 }
                 else
                 {
                     if (oldmoveindex < place && newmoveindex >= place)
                     {
                         place--;
                     }
                     if (oldmoveindex > place && newmoveindex <= place)
                     {
                         place++;
                     }
                 }
                 var newplaylist = new MediaPlaybackList();
                 foreach (Song song in Playlist)
                 {
                     var mediaPlaybackItem = new MediaPlaybackItem(MediaSource.CreateFromStorageFile(await song.GetFile()));
                     newplaylist.Items.Add(mediaPlaybackItem);
                 }
                 newplaylist.CurrentItemChanged += Media.Instance.Playlist_CurrentItemChanged;
                 currenttime = Media.Instance.GetSongTime();
                 Media.Instance.mediaPlayer.Source = newplaylist;
                 Media.Instance.Playlist           = newplaylist;
                 newplaylist.MoveTo((uint)place);
                 SongListStorage.CurrentPlaceInPlaylist = place;
                 Media.Instance.SetSongTime(currenttime);
                 await SongListStorage.SaveNowPlaying();
             }
             catch (InvalidOperationException E)
             {
                 //Debug.Writeline();
             }
         }
         oldmoveindex = -1;
     }
 }
예제 #7
0
        //Plays the playlist
        public async Task LoadNowPlaying(ObservableCollection <Song> Songs, int Pos, TimeSpan time)
        {
            mediaPlayer.Pause();
            Playlist.Items.Clear();                         //Clears the playlist
            SongListStorage.CurrentPlaceInPlaylist = 0;
            SongListStorage.PlaylistRepresentation.Clear(); //MAY BE BAD?

            Song currentsong = Songs[Pos - 1];

            await AddSong(currentsong.ID, false);

            SetSongTime(time);
            bool b = mediaPlayer.PlaybackSession.CanPause;

            //mediaPlayer.Pause();

            await UpdateNowPlaying();

            //bool k .CanPause;


            int counter = 0;

            for (int i = 0; i < Songs.Count; i++)
            {
                var song  = Songs[i];
                var title = song.Title;

                var file = await song.GetFile();

                if (file != null)
                {
                    var mediaPlaybackItem = new MediaPlaybackItem(MediaSource.CreateFromStorageFile(file));

                    if (i < Pos - 1)
                    {
                        Playlist.Items.Insert(counter, mediaPlaybackItem);
                        SongListStorage.PlaylistRepresentation.Insert(counter, song);
                        counter++;
                    }
                    if (i > Pos - 1)
                    {
                        Playlist.Items.Add(mediaPlaybackItem);
                        SongListStorage.PlaylistRepresentation.Add(song);
                    }
                }
            }
            await UpdateNowPlaying();

            //var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            //Listeneventcount = (int)localSettings.Values["Listeneventcount"];
            //SongListenInDB = (bool)localSettings.Values["nowplayingtime"];


            await SongListStorage.SaveNowPlaying();
        }
예제 #8
0
        private async void SortTypeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var NewSort = (SongListStorage.SortType)((((ComboBox)sender).SelectedItem) as ComboBoxItem).Tag;

            if (NewSort != SongListStorage.AlbumListSortType)
            {
                SongListStorage.AlbumListSortType = NewSort;
                await SongListStorage.UpdateAndOrderAlbums(true);
            }
        }
예제 #9
0
 public bool MoveTo(int index)
 {
     if (index >= 0 && index < SongListStorage.PlaylistRepresentation.Count)
     {
         Playlist.MoveTo((uint)index);
         mediaPlayer.Play();
         SongListStorage.SavePlace();
         return(true);
     }
     return(false);
 }
예제 #10
0
        private void PlaybackSession_PositionChanged(MediaPlaybackSession sender, object args)
        {
            var totalticks = SongListStorage.GetCurrentSong().Duration.TotalSeconds * 4;

            if (++Listeneventcount > totalticks / 2 && !SongListenInDB)
            {
                AddListenToDB(SongListStorage.GetCurrentSong().ID);
                SongListenInDB = true;
            }
            SongListStorage.SaveDBInfo(Listeneventcount, SongListenInDB);
        }
예제 #11
0
 private async Task PlayRandomAlbum()
 {
     if (Albums.Count > 0)
     {
         var   rand     = new Random();
         int   chosen   = rand.Next(Albums.Count);
         var   albumkey = Albums[chosen].Key;
         Album album    = SongListStorage.GetPinnedFlavourForAlbum(albumkey);
         await album.Play();
     }
 }
예제 #12
0
        /// <summary>
        /// Invoked when application execution is being suspended.  Application state is saved
        /// without knowing whether the application will be terminated or resumed with the contents
        /// of memory still intact.
        /// </summary>
        /// <param name="sender">The source of the suspend request.</param>
        /// <param name="e">Details about the suspend request.</param>
        private async void OnSuspending(object sender, SuspendingEventArgs e)
        {
            var deferral = e.SuspendingOperation.GetDeferral();
            //TODO: Save application state and stop any background activity
            bool k = false;

            while (!k)
            {
                k = await SongListStorage.SaveNowPlaying();
            }
            //await SongListStorage.SaveFlavours();
            deferral.Complete();
        }
예제 #13
0
 //Dodgy volume stuff
 public void VolChanged()
 {
     if (!hasFixedvol)
     {
         hasFixedvol        = true;
         mediaPlayer.Volume = chosenVol * (globalVol / 10000.0);
     }
     else
     {
         hasFixedvol = false;
     }
     SongListStorage.SaveVolume();
 }
예제 #14
0
        //Plays the specified song
        public async Task PlaySong(string songid)
        {
            Playlist.Items.Clear();
            var song = SongListStorage.SongDict[songid];
            var file = await song.GetFile();

            var mediaPlaybackItem = new MediaPlaybackItem(MediaSource.CreateFromStorageFile(await song.GetFile()));

            Playlist.Items.Add(mediaPlaybackItem);
            mediaPlayer.Play();
            SongListStorage.PlaylistRepresentation.Clear();
            SongListStorage.PlaylistRepresentation.Add(SongListStorage.SongDict[songid]);
            await SongListStorage.SaveNowPlaying();
        }
예제 #15
0
        //Doesn't work for numbers.
        private async void ListViewArtists_KeyDown(object sender, KeyRoutedEventArgs e)
        {
            if (e.Key.ToString() == "Back")
            {
                if (searchterm.Length > 0)
                {
                    searchterm           = searchterm.Remove(searchterm.Length - 1);
                    SearchTextBlock.Text = searchterm;
                }
                return;
            }
            if (e.Key.ToString().Length == 1)
            {
                SearchPopup.IsOpen = true;
                var listview = ListViewArtists;
                searchterm = searchterm + e.Key.ToString().ToUpperInvariant();
                Artist result = null;
                foreach (Artist artist in Artists)
                {
                    if (artist.name.Length >= searchterm.Length && artist.name.Substring(0, searchterm.Length).ToLowerInvariant() == searchterm.ToLowerInvariant())
                    {
                        result = artist;
                        break;
                    }
                }
                if (result == null)
                {
                    var r = SongListStorage.SearchArtists(searchterm);
                    if (r.Count > 0)
                    {
                        result = r[0];
                    }
                }
                if (result != null)
                {
                    listview.ScrollIntoView(result);
                    listview.SelectedItem = result;
                }
                var oldsearchterm = searchterm;
                SearchTextBlock.Text = searchterm;
                await Task.Delay(1000);

                if (searchterm.Equals(oldsearchterm))
                {
                    SearchPopup.IsOpen   = false;
                    searchterm           = "";
                    SearchTextBlock.Text = "";
                }
            }
        }
예제 #16
0
        //Plays the playlist
        public async Task PlayPlaylist(ObservableCollection <Song> Songs, int Pos, string songid, bool play)
        {
            mediaPlayer.Pause();
            Playlist.Items.Clear();                         //Clears the playlist
            SongListStorage.CurrentPlaceInPlaylist = 0;
            SongListStorage.PlaylistRepresentation.Clear(); //MAY BE BAD?
            foreach (Song song in Songs)
            {
                await AddSong(song.ID, false);

                if (play)
                {
                    mediaPlayer.Play();
                }
                else
                {
                    mediaPlayer.Pause();
                }
            }
            if (Pos > 1 && SongListStorage.PlaylistRepresentation.Count >= Pos)
            {
                Playlist.MoveTo((uint)Pos - 1);
            }
            else
            {
                if (songid != null && songid != "")
                {
                    for (int i = 0; i < SongListStorage.PlaylistRepresentation.Count; i++)
                    {
                        if (SongListStorage.PlaylistRepresentation[i].ID == songid)
                        {
                            Playlist.MoveTo((uint)i);
                            break;
                        }
                    }
                }
            }
            if (play)
            {
                mediaPlayer.Play();
            }
            else
            {
                mediaPlayer.Pause();
            }
            //if (!play) mediaPlayer.Pause();
            await SongListStorage.SaveNowPlaying();
        }
예제 #17
0
        private void CurrentArtistsTextBlock_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var songfile = SongListStorage.GetCurrentSong();

            //Navigates to the artist if it exists, otherwise the albumartist.
            if (SongListStorage.ArtistDict.ContainsKey(songfile.ArtistKey))
            {
                ContentFrame.Navigate(typeof(ArtistPage), songfile.ArtistKey);
            }
            else
            {
                if (SongListStorage.ArtistDict.ContainsKey(songfile.AlbumArtist))
                {
                    ContentFrame.Navigate(typeof(ArtistPage), songfile.AlbumArtist);
                }
            }
        }
예제 #18
0
        public async Task UpdateNowPlaying()
        {
            uint position = Playlist.CurrentItemIndex;

            if (position == 4294967295) //Magic number?? Perfectly totient.
            {
                SongListStorage.CurrentPlaceInPlaylist = 0;
            }
            else
            {
                SongListStorage.CurrentPlaceInPlaylist = (int)position;
            }
            if (SongListStorage.PlaylistRepresentation.Count > 0)
            {
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                                            async() =>
                {
                    Currentart = await SongListStorage.GetCurrentSongArt(100);
                }
                                                                                                            );

                Currenttitle  = SongListStorage.GetCurrentSongName();
                Currentartist = SongListStorage.GetCurrentArtistName();

                //set the system transport controls
                //mediaPlayer.SystemMediaTransportControls.IsEnabled = true;
                var props = mediaPlayer.SystemMediaTransportControls.DisplayUpdater;
                props.Type = Windows.Media.MediaPlaybackType.Music;
                //props.AppMediaId = "TOAST";
                //props.MusicProperties.Title = "TEST";
                //props.Update();
                //var musicprops = props.MusicProperties;
                var file = await SongListStorage.GetCurrentSongFile();

                bool ok = await props.CopyFromFileAsync(Windows.Media.MediaPlaybackType.Music, file);

                //props.AppMediaId = "dwioahjdioaw";
                //props.Type = Windows.Media.MediaPlaybackType.Music;
                props.Update();
            }
            SongListStorage.SavePlace();
        }
예제 #19
0
        //Appends a song to the playlist.
        public async Task AddSong(string songid, bool save)
        {
            if (SongListStorage.SongDict.ContainsKey(songid))
            {
                var song = SongListStorage.SongDict[songid];
                var file = await song.GetFile();

                if (file != null)
                {
                    var mediaPlaybackItem = new MediaPlaybackItem(MediaSource.CreateFromStorageFile(file));
                    Playlist.Items.Add(mediaPlaybackItem);
                    SongListStorage.PlaylistRepresentation.Add(SongListStorage.SongDict[songid]);
                }

                if (save)
                {
                    await SongListStorage.SaveNowPlaying();
                }
            }
        }
예제 #20
0
        private void AlbumArtImage_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var songfile = SongListStorage.GetCurrentSong();

            ContentFrame.Navigate(typeof(AlbumPage), songfile.AlbumKey);
        }
예제 #21
0
 private async void AddAlbumToPlaylistButton_Click(object sender, RoutedEventArgs e)
 {
     string albumid = (string)((Button)sender).Tag;
     Album  album   = SongListStorage.GetPinnedFlavourForAlbum(albumid);
     await album.AddToPlaylist();
 }
예제 #22
0
 private async void playalbumButton_Click(object sender, RoutedEventArgs e)
 {
     string albumid = (string)((Button)sender).Tag;
     Album  album   = SongListStorage.GetPinnedFlavourForAlbum(albumid); //SongListStorage.AlbumDict[albumid];
     await album.Play();                                                 //mb 1
 }
예제 #23
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();
        }
예제 #24
0
        //Gets a collection of song files.
        public static async Task GetSongs(bool FirstTime)
        {
            try
            {
                App.GetForCurrentView().DisplayLoading(0, 0, 0, false);
            }
            catch (Exception E)
            {
                Debug.WriteLine("Couldn't display loading bar yet.");
                Debug.WriteLine(E.Message);
            }
            var files = await GetSongList();

            ConcurrentDictionary <String, Song>   SongDict;
            ConcurrentDictionary <String, Artist> ArtistDict;
            ConcurrentDictionary <String, Album>  AlbumDict;

            int songsloaded = 0;

            if (FirstTime)
            {
                SongDict   = SongListStorage.SongDict;
                AlbumDict  = SongListStorage.AlbumDict;
                ArtistDict = SongListStorage.ArtistDict;
            }
            else
            {
                SongDict   = new ConcurrentDictionary <String, Song>();
                ArtistDict = new ConcurrentDictionary <String, Artist>();
                AlbumDict  = new ConcurrentDictionary <String, Album>();
            }

            try
            {
                App.GetForCurrentView().DisplayLoading(0, 0, 0, false);
            }
            catch (Exception E)
            {
                Debug.WriteLine("Couldn't display loading bar yet.");
                Debug.WriteLine(E.Message);
            }


            Regex songreg      = new Regex(@"^audio/");
            int   filesscanned = 0;
            int   songsfound   = 0;

            //foreach (var file in files)
            for (int i = 0; i < files.Count; i++)
            {
                var file = files[i];
                filesscanned++;
                //Checks if it's an audio file
                if (songreg.IsMatch(file.ContentType))
                {
                    songsfound++;
                    if (songsfound % 10 == 0 || songsfound <= 1)
                    {
                        try
                        {
                            App.GetForCurrentView().DisplayLoading(songsfound, files.Count, filesscanned, false);
                        }
                        catch { }
                    }
                    if (songsfound % 50 == 0)
                    {
                        if (FirstTime)
                        {
                            await SongListStorage.UpdateAndOrderMusic();
                        }
                    }
                    MusicProperties musicProperties = await(file as StorageFile).Properties.GetMusicPropertiesAsync();

                    IDictionary <string, object> returnedProps = await file.Properties.RetrievePropertiesAsync(new string[] { "System.Music.PartOfSet" });

                    string discnumber = (string)returnedProps["System.Music.PartOfSet"];
                    if (discnumber == null)
                    {
                        discnumber = "1";
                    }

                    Song song = new Song()
                    {
                        ID          = "",
                        Title       = musicProperties.Title,
                        Album       = musicProperties.Album,
                        AlbumArtist = musicProperties.AlbumArtist,
                        Artist      = musicProperties.Artist,
                        Year        = musicProperties.Year,
                        Duration    = musicProperties.Duration,
                        TrackNumber = (int)musicProperties.TrackNumber,
                        IsFlavour   = false, //MAY NEED TO REMOVE
                        Path        = ((StorageFile)file).Path,
                        DiscNumber  = discnumber
                    };


                    string id    = "";
                    String props = song.Title + song.Album + song.AlbumArtist + song.Artist;
                    id      = props.Replace(",", "");
                    song.ID = id;

                    if (SongDict.TryAdd(id, song))
                    {
                        songsloaded++;
                    }
                    else
                    {
                        Debug.WriteLine("Couldn't add " + song.Title + " by " + song.Artist + " from " + song.Album + ".");
                    }

                    AddAlbum(id, song, SongDict, ArtistDict, AlbumDict);
                }
            }
            if (!FirstTime)
            {
                SongListStorage.SongDict   = SongDict;
                SongListStorage.AlbumDict  = AlbumDict;
                SongListStorage.ArtistDict = ArtistDict;
            }
            else
            {
                await SongListStorage.LoadFlavours();
            }
            await App.GetForCurrentView().ResetFlavours();

            //Should also display a message saying that all files have been loaded.
            Debug.WriteLine("Loaded " + songsloaded + " songs.");
            try
            {
                App.GetForCurrentView().DisplayLoading(songsfound, files.Count, filesscanned, true);
            }
            catch { }
            await SongListStorage.UpdateAndOrderMusic();

            await MusicToJSON();
        }
예제 #25
0
        //Shows song suggestions in the searchbox based on what has been typed.
        private void SearchBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
        {
            if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
            {
                var textresults = new List <StackPanel>();

                //Get Artists
                var artistsresults = SongListStorage.SearchArtists(SearchBox.Text);
                foreach (Artist artist in artistsresults)
                {
                    StackPanel stackpanel = new StackPanel()
                    {
                        Orientation = Orientation.Horizontal
                    };
                    stackpanel.Tag = artist;

                    SymbolIcon symbol = new SymbolIcon()
                    {
                        Symbol = Symbol.Contact,
                        Margin = new Thickness()
                        {
                            Right = 5
                        }
                    };
                    stackpanel.Children.Add(symbol);

                    TextBlock textblock = new TextBlock()
                    {
                        Text = artist.name,
                    };


                    stackpanel.Children.Add(textblock);

                    textresults.Add(stackpanel);
                }

                //Get Albums
                var albumresults = SongListStorage.SearchAlbums(SearchBox.Text, SongListStorage.Albums);
                foreach (Album album in albumresults)
                {
                    StackPanel stackpanel = new StackPanel()
                    {
                        Orientation = Orientation.Horizontal
                    };
                    stackpanel.Tag = album;

                    SymbolIcon symbol = new SymbolIcon()
                    {
                        Symbol = Symbol.Rotate,
                        Margin = new Thickness()
                        {
                            Right = 5
                        }
                    };
                    stackpanel.Children.Add(symbol);

                    TextBlock textblock = new TextBlock()
                    {
                        Text = album.Name,
                    };
                    stackpanel.Children.Add(textblock);

                    /*Button playbutton = new Button()
                     * {
                     *  Content = new SymbolIcon()
                     *  {
                     *      Symbol = Symbol.Play,
                     *      Margin = new Thickness() { Right = 5 },
                     *      Tag = album
                     *  },
                     * };
                     * playbutton.Click += Playbutton_Click;
                     * stackpanel.Children.Add(playbutton);*/


                    textresults.Add(stackpanel);
                }

                //Get Songs
                var songresults = SongListStorage.SearchSongs(SearchBox.Text);
                foreach (Song song in songresults)
                {
                    StackPanel stackpanel = new StackPanel()
                    {
                        Orientation = Orientation.Horizontal
                    };
                    stackpanel.Tag = song;

                    SymbolIcon symbol = new SymbolIcon()
                    {
                        Symbol = Symbol.Audio,
                        Margin = new Thickness()
                        {
                            Right = 5
                        }
                    };
                    stackpanel.Children.Add(symbol);

                    TextBlock textblock = new TextBlock()
                    {
                        Text = song.Title,
                    };
                    stackpanel.Children.Add(textblock);

                    /*Button playbutton = new Button()
                     * {
                     *  Content = new SymbolIcon()
                     *  {
                     *      Symbol = Symbol.Play,
                     *      Margin = new Thickness() { Right = 5 },
                     *      Tag = song
                     *  },
                     * };
                     * playbutton.Click += Playbutton_Click;
                     * stackpanel.Children.Add(playbutton);*/



                    textresults.Add(stackpanel);
                }

                SearchBox.ItemsSource = textresults;
            }
        }