[英]Stream audio using MediaFoundationReader with Naudio
I am using the MediaFoundationReader to play almost every format with my program, but I also read you are able to play streams using this. 我正在使用MediaFoundationReader播放程序中的几乎所有格式,但是我也阅读到您可以使用此程序播放流。 How would you go about reading streams from the internet using MediaFoundationReader?
您将如何使用MediaFoundationReader从Internet阅读流?
When I initialize the MediaFoundationReader-object with an URL I get the following exception: 当我使用URL初始化MediaFoundationReader-object时,出现以下异常:
System.Runtime.InteropServices.COMException (0xC00D001A): Exception from HRESULT: 0xC00D001A
at NAudio.MediaFoundation.MediaFoundationInterop.MFCreateSourceReaderFromURL(String pwszURL, IMFAttributes pAttributes, IMFSourceReader& ppSourceReader)
at NAudio.Wave.MediaFoundationReader.CreateReader(MediaFoundationReaderSettings settings)
at NAudio.Wave.MediaFoundationReader..ctor(String file, MediaFoundationReaderSettings settings)
at NAudio.Wave.MediaFoundationReader..ctor(String file)
The URL, by the way is valid and works when I try it on my web-browser. 顺便说一下,URL是有效的,并且在我在Web浏览器上尝试时可以使用。
The error you are getting is: NS_E_FILE_NOT_FOUND "The system cannot find the file specified." 您遇到的错误是:NS_E_FILE_NOT_FOUND“系统找不到指定的文件。” So check your URL is correctly formatted.
因此,请检查您的URL格式是否正确。
Here's a quick snippet playing audio from a URL with MediaFoundationReader: 以下是使用MediaFoundationReader从URL播放音频的快速片段:
var url = "http://media.ch9.ms/ch9/2876/fd36ef30-cfd2-4558-8412-3cf7a0852876/AzureWebJobs103.mp3";
using(var mf = new MediaFoundationReader(url))
using(var wo = new WaveOutEvent())
{
wo.Init(mf);
wo.Play();
while (wo.PlaybackState == PlaybackState.Playing)
{
Thread.Sleep(1000);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.