Пример #1
0
        private void btnClear_Click(object sender, RoutedEventArgs e)
        {
            List <string> Commands = new List <string>();

            Commands.Add(HelperMethods.SerializeObject(new KodiPlayerStop(MyInfo.CurrentPlayerId)));
            Commands.Add(HelperMethods.SerializeObject(new KodiClearPlayList(MyInfo.CurrentPlaylistId)));
            Task.Factory.StartNew(() => KodiCommand.SendKodiCommandsInOrderAsync(MyInfo.KodiServer, Commands));
            MyInfo.PlaylistEntries.Clear();
            DisplayFadeMessage("Playlist Cleared");
        }
Пример #2
0
 private async void btnAddAll_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         btnAddAll.IsEnabled = false;
         Int32         Counter  = 0;
         List <String> Commands = new List <String>();
         foreach (MusicFolderEntry E in (List <MusicFolderEntry>) this.lvFiles.ItemsSource)
         {
             if (E.filetype == "file" && E.file.ToLower().EndsWith("mp3"))
             {
                 if (FirstRun)
                 {
                     await ProcessFirstRunAsync(E);
                 }
                 else
                 {
                     Commands.Add(HelperMethods.SerializeObject(new KodiAddFileToPlayList(MyInfo.CurrentPlaylistId, E.file)));
                 }
                 this.MyInfo.PlaylistEntries.Add(E);
                 Counter++;
             }
         }
         if (Counter > 0)
         {
             DisplayFadeMessage("Added " + Counter.ToString());
             if (Commands.Count > 0)
             {
                 await Task.Factory.StartNew(() => KodiCommand.SendKodiCommandsInOrderAsync(MyInfo.KodiServer, Commands));
             }
         }
         else
         {
             DisplayFadeMessage("Nothing added!");
         }
     }
     catch (Exception ex)
     {
         var dialog = new MessageDialog(ex.ToString());
         await dialog.ShowAsync();
     }
     finally
     {
         btnAddAll.IsEnabled = true;
     }
 }
Пример #3
0
        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;
        }