For a project I’m working on at work, I had a need for an easy to embed video control into my Silverlight UI – previously I had been using some code hacked out of an Expression Encoder template, but it had a few bugs and didn’t look very nice. I was quite happy then, when Microsoft released the Silverlight Media Framework during PDC09. It’s got a nice UI, it’s easily themeable and embeddable, and a fairly complete player framework (supports things like timeline markers, etc).
Much to my dismay however, I discovered that it was only compatible with IIS Smooth Streaming files, not the standard MP4 files that I had been using. However, they also ship the source, so I have a chance to do some hacking and turns out, it was pretty easy to make this work properly.
index f642d2c..fadd5e6 100755
@@ -725,7 +725,7 @@ namespace Microsoft.SilverlightMediaFramework.Player
maxSelectedStreamBitrate = 0;
// get video stream
- var streamResult = (from stream in SelectedStreams
+ var streamResult = (from stream in SelectedStreams ?? Enumerable.Empty< StreamInfo > ()
where stream.Name == "video"
So, if you don’t grok what this is saying, here’s what it means – download the source, open the
Microsoft.SilverlightMediaFramework.Player/CoreSmoothStreamingMediaElement.cs file, then go to line 728 or so, and replace
"from stream in SelectedStreams" with
"from stream in SelectedStreams ?? Enumerable.Empty<StreamInfo>()". Then, rebuild the project (remember, you have to download Microsoft.Web.Media.SmoothStreaming.dll from here before you’ll be able to build the project.
Once you have the patched SMF, you should be able to play any file by doing something like: