How to access SetRestrictedTracks method on MediaStream

Jan 21, 2011 at 12:06 PM


I found that I need to filter available tracks for the Windows Phone 7 because it only supports tracks with same resolutions. Fortunatelly 2.3 version adds the SetRestrictedTracks method on MediaStream. I was trying to find the best place to implement this filtering. Since I couldn't find any events or properties too hook to, I decided to derrive the SMFPlayer and override the OnManifestReady method (see below). Could you please confirm that this is the correct way to handle this? 

        protected override void OnManifestReady()

            if (ActiveAdaptiveMediaPlugin != null)
                var videoStream = ActiveAdaptiveMediaPlugin.CurrentSegment.SelectedStreams.Where(i => i.Type == StreamType.Video)

                if (videoStream != null && videoStream.AvailableTracks.Any())
                    // check if resolutions are set on all tracks
                    if (videoStream.AvailableTracks.All(i => i.Resolution.IsEmpty))
                        // select first below 1000k
                        var track = videoStream.AvailableTracks
                            .OrderByDescending(i => i.Bitrate)
                            .FirstOrDefault(i => i.Bitrate < 1000000);
                        if (track == null)
                            // select lowest bitrate
                            track = videoStream.AvailableTracks.OrderBy(i => i.Bitrate).FirstOrDefault();

                        videoStream.SetRestrictedTracks(new[] {track});
                        // check if all tracks have same resolution
                        Size resolution = videoStream.AvailableTracks.First().Resolution;
                        if (videoStream.AvailableTracks.All(i => i.Resolution == resolution))

                        // find top track with resolution less then 720x480
                        resolution = videoStream.AvailableTracks
                            .Where(i => i.Resolution.Width <= 720 && i.Resolution.Height <= 480)
                            .OrderByDescending(o => o.Resolution.Width)

                            videoStream.AvailableTracks.Where(o => o.Resolution == resolution));

Feb 9, 2011 at 11:00 AM

I too I'm looking for the answer to this problem, if anyone can provide some assistance, I would appreciate it.

Thank you,

Feb 9, 2011 at 4:42 PM

kobush, yes, call SetRestrictedTracks from OnManifestReady if your videos are not encoded with WP7 in mind. Here is a great blog post with some more info:

On a related note, I will add a suggestion for a future version of SMF to support this internally so you don't have to do this. For now, you're on the right track... pun intended ;)

Tim Greenfield

Feb 9, 2011 at 4:46 PM

Thank you timgreenfield and thank you too kobush.

I was able to implement a rule that allows me to choose the proper track to play, using a modified version of the OP's code.


Feb 10, 2011 at 5:39 AM

Thank you timgreenfield for confirming this. The solution works great so far.

One thing to observe is that we still have some videos encoded with older versions of Expression Encoder, where manifest doesn't provide information on resolution for each tracks. Thats why I made the additional check to see if resolution is set for all tracks, and if its not select track with suitable bitrate instead.

I hope this will be handled by SMF in future version (let me know where I could vote for this :-)


Jun 19, 2011 at 3:44 AM

Szymon, I think the problem you are encountering with the resolution being empty may have to do with V2 manifests using the attribute "MaxWidth", while v1 manifests used "Width" (same goes for height). SMF is currently relying on MaxWidth to populate the resolution property. I've created a bug for this so resolution will now fallback to "Width" if "MaxWidth" isn't found.

Do you happen to have a test manifest I could try out to confirm this will address the issue for you?


Jun 19, 2011 at 4:22 AM

fyi: I just added this feature. It will be available in the next version. Thanks for bringing this up all, hopefully this will prevent some headaches trying to get smooth streaming to work on the phone!

Feature reference: