/// <summary>
 /// A static method used to play the given list of files.
 /// </summary>
 /// <param name="filesToPlay">The list of files to play</param>
 public static void PlayFile(List <string> filesToPlay)
 {
     foreach (var file in filesToPlay)
     {
         int id = MediaPlayProducerConsumer.Instance().WorkLength + 1;
         MediaPlayProducerConsumer.Instance().Produce
         (
             new WorkItem
             (
                 id, file
             )
         );
     }
     MediaPlayProducerConsumer.Instance().Wait();
 }
示例#2
0
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            List <string>  playList = new List <string>();
            TitleViewModel vm       = (sender as MenuItem).DataContext as TitleViewModel;

            if (vm != null)
            {
                // Here we have a single song title so a specific title must have been
                // clicked in the tree.
                // Play the song.
                playList.Add(vm.FilePath + "\\" + vm.FileName);
                MediaPlayProducerConsumer.PlayFile(playList);
            }
            else
            {
                AlbumViewModel am = (sender as MenuItem).DataContext as AlbumViewModel;
                if (am != null)
                {
                    // Play each song title under the clicked album title.

                    // The children (song titles) are not expanded, but since the tree
                    // is using lazy loading on expansion, we need to get the children
                    // without explicily clicking on the window to expand the tree.
                    // If the album is already expanded, don't do this.
                    if (!am.IsExpanded)
                    {
                        am.LoadAction.Invoke();
                    }
                    // Go through each title and load a list with its path
                    // to get to its file to play
                    foreach (var item in am.Children)
                    {
                        TitleViewModel tm = item as TitleViewModel;
                        if (tm != null)
                        {
                            playList.Add(tm.FilePath + "\\" + tm.FileName);
                        }
                    }
                    // Send the list to the player
                    MediaPlayProducerConsumer.PlayFile(playList);
                }
            }
        }
 /// <summary>
 /// The public accessor to the static instance
 /// </summary>
 /// <returns>The static reference</returns>
 public static MediaPlayProducerConsumer Instance()
 {
     return(_instance ?? (_instance = new MediaPlayProducerConsumer()));
 }