Beispiel #1
0
        private void btnPrev_Click(object sender, RoutedEventArgs e)
        {
            //TODO: When these buttons are clicked update playlist to show what's playing
            KodiMoveRequest R = new KodiMoveRequest(MyInfo.CurrentPlayerId, "left");

            Task.Factory.StartNew(() => KodiCommand.SendKodiCommandAsync(MyInfo.KodiServer, HelperMethods.SerializeObject(R)));
        }
Beispiel #2
0
 private void btnPlaylistDeleteEntry_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         MusicFolderEntry item = (MusicFolderEntry)(sender as FrameworkElement).DataContext;
         int index             = lvPlaylist.Items.IndexOf(item);
         KodiCommand.SendKodiCommandAsync(MyInfo.KodiServer, HelperMethods.SerializeObject(new KodiRemoveItemFromPlaylist(MyInfo.CurrentPlaylistId, index)));
         foreach (MusicFolderEntry listitem in MyInfo.PlaylistEntries)
         {
             if (listitem.file == item.file)
             {
                 MyInfo.PlaylistEntries.Remove(listitem);
                 break;
             }
         }
         lvPlaylist.ItemsSource = null;
         BindingOperations.SetBinding(lvPlaylist, ListView.ItemsSourceProperty, new Binding()
         {
             Source = MyInfo.PlaylistEntries, Mode = BindingMode.OneWay
         });
         lvPlaylist.ScrollIntoView(item);
     }
     catch (Exception ex)
     {
         LogMessage("Error " + ex.ToString());
     }
 }
Beispiel #3
0
        private async Task <Boolean> SyncPlaylistWithKodi(Int32 PlaylistId)
        {
            KodiPlayListItemsRequest  ItemsInList = new KodiPlayListItemsRequest(PlaylistId);
            KodiPlayListItemsResponse Response    = await KodiCommand.GetPlaylistItems(MyInfo.KodiServer, ItemsInList);

            if (Response.result.items != null && Response.result.items.Count() > 0)
            {
                MyInfo.PlaylistEntries.Clear();
                //Pull in existing items
                foreach (KodiPlayListItem I in Response.result.items)
                {
                    MusicFolderEntry E = new MusicFolderEntry()
                    {
                        Line1Display = I.title, file = I.file, Line2Display = I.file, Track = I.track
                    };
                    if (I.artist != null && I.artist.Count() > 0)
                    {
                        E.Line2Display = I.artist[0];
                    }
                    this.MyInfo.PlaylistEntries.Add(E);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
        private async void btnRandom_Click(object sender, RoutedEventArgs e)
        {
            KodiSetShuffle R = new KodiSetShuffle(MyInfo.CurrentPlayerId);
            await Task.Factory.StartNew(() => KodiCommand.SendKodiCommandAsync(MyInfo.KodiServer, HelperMethods.SerializeObject(R)));

            await SyncPlaylistWithKodi(MyInfo.CurrentPlaylistId);

            DisplayFadeMessage("Shuffle Toggled");
        }
Beispiel #5
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");
        }
Beispiel #6
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;
     }
 }
Beispiel #7
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;
        }
Beispiel #8
0
        public async Task <List <MusicFolderEntry> > GetFolderEntries(String Folder)
        {
            List <MusicFolderEntry> Entries = new List <MusicFolderEntry>();

            try
            {
                if (MyInfo.FolderCache.Exists(Folder))
                {
                    Entries = MyInfo.FolderCache.FromCache(Folder);
                }
                else
                {
                    KodiDirectoryRequest Req = new KodiDirectoryRequest()
                    {
                        id = 1
                    };
                    Req._params.directory = Folder;
                    //Use folder structure at the top, then library structure as we get deeper
                    if (!MyInfo.MediaFolders.ShouldDisplayWithFolderStructure)
                    {
                        Req._params.media = "music";
                    }
                    KodiFileResponse FileList = await KodiCommand.GetDirectoryContents(MyInfo.KodiServer, Req);

                    foreach (KodiFileEntry E in FileList.result.files)
                    {
                        MusicFolderEntry M = new MusicFolderEntry();
                        if (FormatFolderEntry(Folder, E, M))
                        {
                            Entries.Add(M);
                        }
                    }
                    MyInfo.FolderCache.ToCache(Folder, Entries);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Could not get folders from Kodi", ex);
            }
            return(Entries);
        }
Beispiel #9
0
        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);
                    }
                }
            }
        }
Beispiel #10
0
        private void btnPlayPause_Click(object sender, RoutedEventArgs e)
        {
            KodiPlayPauseRequest R = new KodiPlayPauseRequest(MyInfo.CurrentPlayerId);

            Task.Factory.StartNew(() => KodiCommand.SendKodiCommandAsync(MyInfo.KodiServer, HelperMethods.SerializeObject(R)));
        }