RestrictTracks Method

Replaces AvailableTracks with the list of available tracks supplied by the parameter. Also restricts decoder initialization to the given list of available tracks to avoid initializing the decoder with unsupported modes.

Namespace:  Microsoft.Web.Media.SmoothStreaming
Assembly:  Microsoft.Web.Media.SmoothStreaming (in Microsoft.Web.Media.SmoothStreaming.dll)

public void RestrictTracks(
	IList<TrackInfo> availableTracks


Type: System.Collections.Generic..::..IList<(Of <(<'TrackInfo>)>)>
A new list of available tracks. The list must be a strict subset of current AvailableTracks.

The SelectTracks(IList<(Of <<'(TrackInfo>)>>), Boolean) method will automatically be called with the given list of available tracks. Note that SelectedTracks will not be updated until after the ManifestReady event. Only video track restriction is supported in this release.

The RestrictTracks(IList<(Of <<'(TrackInfo>)>>)) method is used to work around some of the limitations of Windows Phone 7. Windows Phone 7 does not support dynamic resolution changes, and H264 support extends only to level 3.0. These are Windows Phone 7 limitations, not specific to the Smooth Streaming Media Element.

The following example restricts tracks to tracks of the same resolution.

void OnManifestReady(object sender, EventArgs e)
    SmoothStreamingMediaElement ssme = sender as SmoothStreamingMediaElement;

    if (ssme == null)

    // Select the highest band of tracks which all have the same resolution.
    // maxMobileBitrate depends on the encoding settings
    const ulong maxMobileBitrate = 1000000; 
    foreach (SegmentInfo segment in ssme.ManifestInfo.Segments)
        foreach (StreamInfo streamInfo in segment.AvailableStreams)
            if (MediaStreamType.Video == streamInfo.Type)
                List<TrackInfo> widestBand = new List<TrackInfo>();
                List<TrackInfo> currentBand = new List<TrackInfo>();
                ulong lastHeight = 0;
                ulong lastWidth = 0;
                ulong index = 0;

                foreach (TrackInfo track in streamInfo.AvailableTracks)
                    index += 1;

                    string strMaxWidth;
                    string strMaxHeight;
                    // If can't find width/height, choose only the top bitrate.
                    ulong ulMaxWidth = index; 
                    // If can't find width/height, choose only the top bitrate.
                    ulong ulMaxHeight = index; 
                    // V2 manifests require "MaxWidth", while v1 manifests used "Width".
                    if (track.Attributes.TryGetValue("MaxWidth", out strMaxWidth) ||
                        track.Attributes.TryGetValue("Width", out strMaxWidth))
                        ulong.TryParse(strMaxWidth, out ulMaxWidth);

                    if (track.Attributes.TryGetValue("MaxHeight", out strMaxHeight) ||
                        track.Attributes.TryGetValue("Height", out strMaxHeight))
                        ulong.TryParse(strMaxHeight, out ulMaxHeight);

                    if (ulMaxWidth != lastWidth ||
                        ulMaxHeight != lastHeight)
                        // Current band is now finished, check if it is the widest.
                        // If same size, current band preferred over previous
                        // widest, because it will be of higher bitrate.
                        if (currentBand.Count >= widestBand.Count)
                            //  A new widest band:
                            widestBand = currentBand;
                            currentBand = new List<TrackInfo>();

                    if (track.Bitrate > maxMobileBitrate)

                    // Current track always gets added to current band.
                    lastWidth = ulMaxWidth;
                    lastHeight = ulMaxHeight;

                if (0 == widestBand.Count &&
                    0 == currentBand.Count)
                    // Lowest bitrate band is > maxMobileBitrate.
                else if (currentBand.Count >= widestBand.Count)
                    // Need to check the last band which was constructed.
                    Debug.Assert(currentBand.Count > 0);
                    widestBand = currentBand; // Winner by default.

                Debug.Assert(widestBand.Count >= 1);

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.0