private async Task ProcessFirstRunAsync(MusicFolderEntry Entry) { try { List <String> Commands; Boolean PlaylistExists = await SyncPlaylistWithKodi(MyInfo.CurrentPlaylistId); //Does a playlist with entries exist in Kodi? KodiAddFileToPlayList AddRequest = new KodiAddFileToPlayList(MyInfo.CurrentPlaylistId, Entry.file); if ((!PlaylistExists || MyInfo.PlaylistEntries.Count == 0)) { //If playlist id does not exist or has no entries, then create it. Commands = new List <string>(); Commands.Add(HelperMethods.SerializeObject(new KodiClearPlayList(MyInfo.CurrentPlaylistId))); Commands.Add(HelperMethods.SerializeObject(AddRequest)); Commands.Add(HelperMethods.SerializeObject(new KodiOpenPlayList(MyInfo.CurrentPlaylistId, 0))); await KodiCommand.SendKodiCommandsInOrderAsync(MyInfo.KodiServer, Commands); this.MyInfo.PlaylistEntries.Add(Entry); } else { //Playlist exists and may have entries, add file to end and resync await KodiCommand.SendKodiCommandAsync(MyInfo.KodiServer, HelperMethods.SerializeObject(AddRequest)); await SyncPlaylistWithKodi(MyInfo.CurrentPlaylistId); //If something is not already playing then start playlist at currently added file KodiActivePlayersResponse Resp = await KodiCommand.GetActivePlayers(MyInfo.KodiServer); if (Resp.result == null || Resp.result.Length == 0) { await KodiCommand.SendKodiCommandAsync(MyInfo.KodiServer, HelperMethods.SerializeObject(new KodiOpenPlayList(MyInfo.CurrentPlaylistId, this.MyInfo.PlaylistEntries.Count()))); } } //Set repeat mode to true await Task.Factory.StartNew(() => KodiCommand.SendKodiCommandAsync(MyInfo.KodiServer, HelperMethods.SerializeObject(new KodiSetRepeat(MyInfo.CurrentPlayerId, "all")))); } catch (Exception ex) { ShowErrorMessageAsync(ex); } this.FirstRun = false; }
private async void btnListViewEntry_ClickAsync(object sender, RoutedEventArgs e) { MusicFolderEntry Entry = ((HomeScreen.MusicFolderEntry)((Windows.UI.Xaml.FrameworkElement)sender).DataContext); if (Entry.filetype.ToLower() == "directory") { MyInfo.MediaFolders.NextFolder(Entry.file); LoadFileEntries(); } if (Entry.filetype.ToLower() == "file") { //Update the screen - This provides visual feedback but is not kept in sync during folder browsing Windows.UI.Xaml.Controls.Button TheButton = ((Windows.UI.Xaml.Controls.Button)sender); Windows.UI.Xaml.Controls.Image ButtonImage = ((Windows.UI.Xaml.Controls.Image)TheButton.Content); ButtonImage.Source = new BitmapImage(new Uri(this.BaseUri, "/Assets/musiccheck.png")); if (this.FirstRun) { //First song you clicked on since the app started ProcessFirstRunAsync(Entry); } else { //Is something playing? KodiActivePlayersResponse Response = await KodiCommand.GetActivePlayers(MyInfo.KodiServer); if (Response.result.Length == 0) { ProcessFirstRunAsync(Entry); } else { //Add file to end of playing list... KodiAddFileToPlayList AddRequest = new KodiAddFileToPlayList(MyInfo.CurrentPlaylistId, Entry.file); Task.Factory.StartNew(() => KodiCommand.SendKodiCommandAsync(MyInfo.KodiServer, HelperMethods.SerializeObject(AddRequest))); this.MyInfo.PlaylistEntries.Add(Entry); } } } }