SubProgram Count and WP 8.1 Support

Dec 30, 2014 at 12:40 PM
Hello everyone , I have 2 questions regarding to my project.

1) Will there be Windows Phone 8.1 support for PhoneSM ?
2) I need to count SubPrograms before switching to higher / lower bandwith.I know that PlaylistSegmentManagerPolicy automatically selects the higher bandwith by default , but I'm trying to get the information for if is there any other bandwith option.How can I achieve this ?

Thank you for your kind answers :)
Coordinator
Dec 30, 2014 at 9:52 PM
bkaankose wrote:
Hello everyone , I have 2 questions regarding to my project.

1) Will there be Windows Phone 8.1 support for PhoneSM ?
There is support for WP8.1 in the latest source and in the latest alpha build. The Win8.1 apps have been converted to Universal apps (HlsView and SamplePlayer). A WP8.1 background audio client has been added to the source. The WP8.1 background audio client is not yet in a binary build since there are sometimes unmanaged memory leaks.
2) I need to count SubPrograms before switching to higher / lower bandwith.I know that PlaylistSegmentManagerPolicy automatically selects the higher bandwith by default , but I'm trying to get the information for if is there any other bandwith option.How can I achieve this ?
The default behavior is to pick whichever stream is first. The example under "Selecting the Stream" shows how to make it pick the stream with the highest bandwidth. If you need it to do something else, you can supply any method that can be assigned to SelectSubProgram (which is "Func<IEnumerable<ISubProgram>, ISubProgram>"). The actual object passed to the callback is a List<ISubProgram>, so multiple evaluations and such are perfectly safe (even if it wasn't, one could always call ".ToArray()"). I would suggest avoiding any blocking calls in the SelectSubProgram handler.

(Yes, it should probably be a member in some kind of policy object instead of a static, but it was implemented before phonesm was restructured to use a dependency injection container.)
Thank you for your kind answers :)
You're welcome.
Coordinator
Jan 11, 2015 at 10:52 PM
Here's a more complicated example using the current code (where "PlaylistSegmentManagerPolicy" became "HlsPlaylistSegmentManagerPolicy"):
    void InitializeMediaStream()
    {
        if (null != _mediaStreamFacade)
            return;

        _mediaStreamFacade = MediaStreamFacadeSettings.Parameters.Create();

        HlsPlaylistSegmentManagerPolicy.SelectSubProgram = programs =>
        {
            var saneStreams = programs
                .Where(p => p.Bandwidth < 7000000 && (!p.Width.HasValue || p.Width.Value <= 1920))
                .ToArray();

            var count = saneStreams.Length;

            return count < 1 ? null : saneStreams[count / 2];
        };

        _mediaStreamFacade.StateChange += TsMediaManagerOnStateChange;
    }
This one selects a specific bandwidth (if the member is set):
    long[] _availableBandwidths;
    long? _requestedBandwidth;

    void InitializeMediaStream()
    {
        if (null != _mediaStreamFacade)
            return;

        _mediaStreamFacade = MediaStreamFacadeSettings.Parameters.Create();

        HlsPlaylistSegmentManagerPolicy.SelectSubProgram = OnSelectSubProgram;

        _mediaStreamFacade.StateChange += TsMediaManagerOnStateChange;
    }

    ISubProgram OnSelectSubProgram(IEnumerable<ISubProgram> programs)
    {
        var saneStreams = programs
            .Where(p => p.Bandwidth < 7000000 && (!p.Width.HasValue || p.Width.Value <= 1920))
            .ToArray();

        if (saneStreams.Length < 1)
        {
            _availableBandwidths = null;

            return null;
        }

        _availableBandwidths = saneStreams
            .Select(ss => ss.Bandwidth)
            .ToArray();

        if (_requestedBandwidth.HasValue)
        {
            var requestedBandwidth = _requestedBandwidth.Value;

            var requestedStream = saneStreams.FirstOrDefault(ss => ss.Bandwidth == requestedBandwidth);

            if (null != requestedStream)
                return requestedStream;
        }

        return saneStreams.FirstOrDefault();
    }