MF streaming

Dec 11, 2012 at 8:16 AM

Hello,

In the series Mediafoundation ;-)


I did a little test streaming (http://radio.reaper.fm/stream/) under MediaFoundationReader.

It works. you just change a few little routine GetLength.


I did not find any indication of loading buffer.

 

Modification ::: MediaFoudationReader.cs

Add :

// Detect if Streaming
private bool IsStreamingUrl = false;

In CreateReader :
protected virtual IMFSourceReader CreateReader(MediaFoundationReaderSettings settings)
{
//var uri = new Uri(file);
			
        IMFSourceReader reader;

	//string fileTest = "http://radio.reaper.fm/stream/";
		
// change for FileName with a Accent
	Uri nUrl = null;
	string str = "";
	if (Uri.TryCreate(file, UriKind.Absolute, out nUrl))
	{
		str = nUrl.ToString();
	}
	else
	{
		str = nUrl.AbsoluteUri;
	}

// Detect Mode Streaming
if (nUrl.Scheme != "file")
	IsStreamingUrl = true;

   MediaFoundationInterop.MFCreateSourceReaderFromURL(str, null, out reader);

........
}



In GetLength :

 private long GetLength(IMFSourceReader reader)
 {
	if (IsStreamingUrl)
		return 0;  // Return 0 !!!!
....

}

Coordinator
Dec 11, 2012 at 2:31 PM

good idea. I've implemented it a little differently, as sometimes streaming MP3 can report its duration. Basically we check if the duration presentation attribute is available and if so we use it