Select quality

Mar 19, 2014 at 10:05 PM
Hi Henric,
Thank you by your library. I'm going to add the function of select the quality of video to my App. Could I select the quality? if it is possible, How should I do it?
Thank you again and sorry by my level of english.
Coordinator
Mar 19, 2014 at 10:59 PM
You're welcome.

You can select the bandwidth by setting PlaylistSegmentManagerPolicy.SelectSubProgram before playback starts.

The default implementation simply picks the first thing it finds in the master playlist. If instead you want to play the highest bandwidth alternative, then you can do something like this:
PlaylistSegmentManagerPolicy.SelectSubProgram =
    programs => programs.OrderByDescending(p => p.Bandwidth)
                        .FirstOrDefault();
or if you prefer,
PlaylistSegmentManagerPolicy.SelectSubProgram =
    programs => (from program in programs
                 orderby program.Bandwidth descending
                 select program)
        .FirstOrDefault();

If you need to do something more complicated, you can override the default IPlaylistSegmentManagerPolicy implementation using the builder:
_mediaStreamFascade.Builder.RegisterSingleton<IPlaylistSegmentManagerPolicy, YourCustomPlaylistSegmentManagerPolicy>();
or
_mediaStreamFascade.Builder.RegisterSingleton((IPlaylistSegmentManagerPolicy)someInstance);
To change it while playing is something I'll be working on shortly. See this discussion for more details on that.
Marked as answer by cansado2930 on 4/3/2014 at 2:19 PM
Apr 3, 2014 at 9:19 PM
Hi Henric,
I have updated your library in my Project and I have found it in the class "HlsPlaylistSegmentManagerPolicy". In the versión that I had used, it was in MediaElement and I could Access to IsolatedStorageSettings. Now I can't do it. I'm sure that the answer is very easy but I have little experiencia yet. My objectiv is that the quality configuration is saved in isolatedStorageSettings and when the player go to Start the video, check the configuration and select the quality.
Thank you again.
Coordinator
Apr 4, 2014 at 1:44 AM
Are you trying to reference something from your SelectSubProgram implementation or are you trying to switch the SelectSubProgram implementation based on your configuration setting? It shouldn't matter that SelectSubProgram has moved; the important part is how the handler is defined. Where are you putting the code that sets SelectSubProgram?
Apr 4, 2014 at 9:07 AM
Hi Henric,
I'm trying to do the second. In the old versión that I had used, modified in your code code, because I haven't enough knowledge in order to do a handler to change this.. If it is possible, I will put it in mi Project, in the same class where player is. Then, How should I do the handler in order to set the quality? Sorry by my lack of knowledge.
Thank you again
Coordinator
Apr 4, 2014 at 12:04 PM
You don't need to modify the phonesm code. You can just set the thing where it is convenient for your code. For example, if you have a "Play" clicked handler somewhere, then you can set it before assigning Source or calling MediaElement.Play(). If you don't have a using statement, you will need to specify the namespace (so, for the current HEAD, you would need to use SM.Media.Hls.HlsPlaylistSegmentManagerPolicy.SelectSubProgram), but it is probably simpler to add "using SM.Media.Hls;" to your implementation file. If you find it simpler to reason about "normal" methods, you could create a member in your own class like so:
using SM.Media.Playlists;
...
ISubProgram MyOwnFunctionThatSelectsTheRightBandwidth(IEnumerable<ISubProgram> programs)
{
   // Do stuff here to select a program from programs
   // Keep in mind that this function will get called from an arbitrary thread.

   var program = ... some code ...

   return program;
}
...
then you would assign it,
using SM.Media.Hls;
...
void SomeSetupFunctionInYourOwnCode()
{
   HlsPlaylistSegmentManagerPolicy.SelectSubProgram = MyOwnFunctionThatSelectsTheRightBandwidth;
}
Apr 7, 2014 at 8:02 PM
Hi Henric,
The first thing of all, thank you very much by your help. I can understand it, so I can develop it in the Windows phone version, but in the case of Windows 8, I can't do it, because SM.Media.HLS doesn't exist in the main version. If I use the last version, I don't find where I set URL of video. How should I do it?
Thank you again
Coordinator
Apr 7, 2014 at 9:49 PM
The "Playlists" directory was getting a bit big and mixed general playlist-related code with HLS-specific code so, between the phonesm-1.2.2 build and the current HEAD, I moved and renamed the class (6e59fb343182 changed it from SM.Media.Playlists.PlaylistSegmentManagerPolicy to SM.Media.Hls.HlsPlaylistSegmentManagerPolicy).

If you are using the phonesm-1.2.2 build or code from before 6e59fb343182 then the above example would look like this instead:
using SM.Media.Playlists;
...
void SomeSetupFunctionInYourOwnCode()
{
   PlaylistSegmentManagerPolicy.SelectSubProgram = MyOwnFunctionThatSelectsTheRightBandwidth;
}