Пример #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
        /// <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)
        {
            Mediafile mp3File = path as Mediafile;

            if (RecentlyPlayedCollection.Elements.Any(t => t.Path == mp3File.Path))
            {
                RecentlyPlayedCollection.Elements.Remove(RecentlyPlayedCollection.Elements.First(t => t.Path == mp3File.Path));
                db.recent.Delete(t => t.Path == mp3File.Path);
            }
            RecentlyPlayedCollection.AddItem(mp3File);
            db.recent.Insert(mp3File);
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                var mp3 = TracksCollection.Elements.Where(t => t.State == PlayerState.Playing);
                if (PlaylistVM.IsPageLoaded)
                {
                    mp3 = PlaylistVM.Songs.Where(t => t.State == PlayerState.Playing);
                }
                if (mp3 != null)
                {
                    foreach (var a in mp3)
                    {
                        a.State = PlayerState.Stopped;
                    }
                }
                StorageFile file = await StorageFile.GetFileFromPathAsync(mp3File.path);
                ShellVM.Play(null, mp3File);
            });

            mp3File.State = PlayerState.Playing;
        }
Пример #3
0
        private async void Elements_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            await Task.Delay(1000);

            if (RecentlyPlayedCollection.Count <= 100)
            {
                RecentlyPlayedCollection.RemoveAt(RecentlyPlayedCollection.Count + 1);
            }
        }
Пример #4
0
 /// <summary>
 /// Loads library from the database file.
 /// </summary>
 void LoadLibrary()
 {
     OptionItems.Add(new ContextMenuCommand(AddToPlaylistCommand, "New Playlist"));
     if (File.Exists(ApplicationData.Current.LocalFolder.Path + @"\breadplayer.db") && Database.IsValid)
     {
         RecentlyPlayedCollection.AddRange(Database.recent.FindAll());
         LoadPlaylists();
         AlphabetList = "&#ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray().Select(x => x.ToString()).ToList();
     }
 }
Пример #5
0
 /// <summary>
 /// Loads library from the database file.
 /// </summary>
 void LoadLibrary()
 {
     GetSettings();
     OptionItems.Add(new ContextMenuCommand(AddToPlaylistCommand, "New Playlist"));
     if (File.Exists(ApplicationData.Current.LocalFolder.Path + @"\breadplayer.db"))
     {
         RecentlyPlayedCollection.AddRange(LibraryService.GetRecentCollection().FindAll());
         LoadPlaylists();
         UpdateJumplist("Title");
     }
 }
Пример #6
0
 public void Dispose()
 {
     Database.Dispose();
     TracksCollection.Clear();
     RecentlyPlayedCollection.Clear();
     ShellVM.PlaylistsItems.Clear();
     OldItems = null;
     PlaylistCollection.Clear();
     OptionItems.Clear();
     GenreCollection.Clear();
 }
Пример #7
0
 public void Reset()
 {
     LibraryService.Dispose();
     LibraryService = null;
     TracksCollection.Clear();
     RecentlyPlayedCollection.Clear();
     GenreFlyout?.Items.Clear();
     PlaylistsItems?.Clear();
     OldItems = null;
     PlaylistCollection.Clear();
     OptionItems.Clear();
     GenreCollection.Clear();
     SongCount = -1;
 }
Пример #8
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);
 }
Пример #9
0
 /// <summary>
 /// Loads library from the database file.
 /// </summary>
 async void LoadLibrary()
 {
     if (File.Exists(ApplicationData.Current.LocalFolder.Path + @"\breadplayer.db"))
     {
         //OldItems = db.GetTracks();
         TracksCollection = new GroupedObservableCollection <string, Mediafile>(t => t.Title, await db.GetTracks(), t => t.Title);
         RecentlyPlayedCollection.AddRange(db.recent.FindAll());
         if (TracksCollection.Elements.Count > 0)
         {
             MusicLibraryLoaded.Invoke(this, new RoutedEventArgs());                                     //no use raising an event when library isn't ready.
         }
         ViewSource.Source          = TracksCollection.Elements;
         ViewSource.IsSourceGrouped = false;
     }
 }
Пример #10
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));
                    }
                });
            }
        }