Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter the name of the file to play.");
            string filename = Console.ReadLine();

            if (filename.StartsWith("\""))
            {
                filename = filename.Remove(0, 1);
            }
            if (filename.EndsWith("\""))
            {
                filename = filename.Remove(filename.Length - 1);
            }
            if (!File.Exists(filename))
            {
                Console.WriteLine("File not found.");
                Environment.Exit(0);
            }
            MediaFoundationProvider provider = new MediaFoundationProvider(filename);
            MediaFoundationPlayer   player   = new MediaFoundationPlayer();

            player.Init(provider);
            while (!player.Prepared)
            {
            }
            player.PlayFromBegining();
            while (player.PlaybackState != NAudio.Wave.PlaybackState.Stopped)
            {
            }
        }
Esempio n. 2
0
        public void CanPlay()
        {
            string url = @"G:\Chevy\Music\Unravel.mp3";

            if (!File.Exists(url))
            {
                Assert.Ignore("Missing test file");
            }
            MediaFoundationProvider provider = new MediaFoundationProvider(url);
            MediaFoundationPlayer   player   = new MediaFoundationPlayer();

            player.Init(provider);
            while (!player.Prepared)
            {
            }
            player.Play();
        }
 protected override Task Play(PlayerCommand cmd)
 {
     if (mmDevice != null)
     {
         var url = $"{musicServerUrl}/{cmd.StreamUrl}";
         log.Debug($"request to call {url}");
         mfp?.Dispose();
         if (playerConfiguration.CacheBeforePlaying)
         {
             mfp = new FilePlayer(url, cmd, LocalStore, GetDevice(mmDevice), loggerFactory.CreateLogger <FilePlayer>());
         }
         else
         {
             mfp = new StreamPlayer(url, cmd, GetDevice(mmDevice), loggerFactory.CreateLogger <StreamPlayer>());
         }
         mfp.PlayerConfiguration = playerConfiguration;
         mfp.PlaybackStarting   += Mfp_PlaybackStarting;
         mfp.PlaybackStopped    += Mfp_PlaybackStopped;
         mfp.PlayAsync();
     }
     return(Task.CompletedTask);
 }