Пример #1
0
 /// <summary>
 /// Plays the selected file. <seealso cref="PlayCommand"/>
 /// </summary>
 /// <param name="path"><see cref="BreadPlayer.Models.Mediafile"/> to play.</param>
 public async void Play(object path)
 {
     if (path is Mediafile)
     {
         Mediafile mp3File = path as Mediafile;
         if (RecentlyPlayedCollection.Any(t => t.Path == mp3File.Path))
         {
             RecentlyPlayedCollection.Remove(RecentlyPlayedCollection.First(t => t.Path == mp3File.Path));
         }
         if (Database.recent.Exists(t => t._id == mp3File._id))
         {
             Database.recent.Delete(t => t._id == mp3File._id);
         }
         RecentlyPlayedCollection.Add(mp3File);
         Database.recent.Insert(mp3File);
         await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
         {
             ShellVM.Load(mp3File, true);
             (PlayCommand as RelayCommand).IsEnabled = false;
             await Task.Delay(100);
             (PlayCommand as RelayCommand).IsEnabled = true;
         });
     }
     //mp3File.State = PlayerState.Playing;
 }
Пример #2
0
 private void AddToRecentCollection(Mediafile mediaFile)
 {
     LibraryService   = new LibraryService(new DatabaseService());
     RecentCollection = LibraryService.GetRecentCollection();
     if (RecentlyPlayedCollection.Any(t => t.Path == mediaFile.Path))
     {
         RecentlyPlayedCollection.Remove(RecentlyPlayedCollection.First(t => t.Path == mediaFile.Path));
     }
     if (RecentCollection.Exists(t => t.Path == mediaFile.Path))
     {
         RecentCollection.Delete(t => t.Path == mediaFile.Path);
     }
     RecentlyPlayedCollection.Add(mediaFile);
     RecentCollection.Insert(mediaFile);
 }
Пример #3
0
        /// <summary>
        /// Plays the selected file. <seealso cref="PlayCommand"/>
        /// </summary>
        /// <param name="path"><see cref="BreadPlayer.Models.Mediafile"/> to play.</param>
        public async void Play(object path)
        {
            if (path is Mediafile)
            {
                LibraryService   = new LibraryService(new DatabaseService());
                RecentCollection = LibraryService.GetRecentCollection();
                Mediafile mp3File = path as Mediafile;
                if (RecentlyPlayedCollection.Any(t => t.Path == mp3File.Path))
                {
                    RecentlyPlayedCollection.Remove(RecentlyPlayedCollection.First(t => t.Path == mp3File.Path));
                }
                if (RecentCollection.Exists(t => t.Path == mp3File.Path))
                {
                    RecentCollection.Delete(t => t.Path == mp3File.Path);
                }
                RecentlyPlayedCollection.Add(mp3File);
                RecentCollection.Insert(mp3File);

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    Messenger.Instance.NotifyColleagues(MessageTypes.MSG_PLAY_SONG, new List <object>()
                    {
                        mp3File, true
                    });
                    (PlayCommand as RelayCommand).IsEnabled = false;
                    await Task.Delay(100);
                    (PlayCommand as RelayCommand).IsEnabled = true;

                    if (TracksCollection.Elements.FirstOrDefault(t => t.Path == Player?.CurrentlyPlayingFile?.Path) != null)
                    {
                        TracksCollection.Elements.FirstOrDefault(t => t.Path == Player?.CurrentlyPlayingFile?.Path).State = PlayerState.Playing;
                        LibraryService.UpdateMediafile(TracksCollection.Elements.FirstOrDefault(t => t.Path == Player?.CurrentlyPlayingFile?.Path));
                    }
                });
            }
        }