PocAsioFFMpegHttpSeekingPlayback.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // See https://aka.ms/new-console-template for more information
  2. using System;
  3. using System.Threading;
  4. using Bmp.Core.Common.Net;
  5. using Bmp.Core.NAudioExt;
  6. using Bmp.Core.Playback.Inputs;
  7. using NAudio.Wave;
  8. using AsioOut = Bmp.Core.Playback.Outputs.NAudioASIO.AsioOut;
  9. using static Bmp.Poc.Const;
  10. namespace Bmp.Poc.PoCs;
  11. internal class PocAsioFFMpegHttpSeekingPlayback
  12. {
  13. public static void MainFunc()
  14. {
  15. var asioDriverName = "Creative SB USB RT ASIO Device";
  16. var shs = new SeekableHttpStream(UrlFlac24Bit96Khz);
  17. var source = new FFMPEGAudioReader(shs);
  18. //var source = new NAudioFFMPEGAudioReader(UrlFlac24Bit96Khz);
  19. var sourceBitPerRawSample = source.BitPerRawSample;
  20. var vdWrap = new VisualizeDataMiddleWrap(source);
  21. var vdSourceBitPerRawSample = source.BitPerRawSample;
  22. var driverNames = AsioOut.GetDriverNames();
  23. var driverIndex = Array.IndexOf(driverNames, asioDriverName);
  24. var outputDevice = new AsioOut(driverIndex);
  25. vdWrap.DataTransferred += (_, args) =>
  26. {
  27. Console.WriteLine($"{DateTime.Now:HH:mm:ss.ff} {nameof(vdWrap.DataTransferred)}:{args.Bytes.Length}");
  28. };
  29. outputDevice.Init(vdWrap);
  30. outputDevice.Play();
  31. while (outputDevice.PlaybackState == PlaybackState.Playing)
  32. {
  33. Console.WriteLine($"{source.CurrentTime}/{source.TotalTime}");
  34. Thread.Sleep(3000);
  35. outputDevice.Pause();
  36. source.CurrentTime = source.CurrentTime.Add(TimeSpan.FromSeconds(1));
  37. Thread.Sleep(100);
  38. outputDevice.Play();
  39. }
  40. }
  41. }