This project has moved and is read-only. For the latest updates, please go here.

Universal MediaPlayer for both mp4 and m3u8 streams?

Jun 16, 2014 at 1:41 PM
Edited Jun 16, 2014 at 3:11 PM
Hi, We're developing quite large WP8 app using the Player Framework SDK. The app should support either standard mp4 online streams and also HLS-AES encoded streams.

The problem is when I tried adding the <smmedia:StreamingMediaPlugin /> tag to our app, it works but only for HLS streams - standard .mp4 streams cannot be played in this configuration. When I remove the plugin, standard streams work but the HLS not.

What is the recommended solution if I want to play either HLS or mp4 streams in single MEdiaPlayer instance? Thanks.

Using version 3f10167c3029 from git, built for WP8.

Edit: Although the basic playback for HLS streams works, When I seek in it, pause, resume or leave the page, I'm getting various exceptions in the library.

Is there any documentation or best practices, how to:
  • save player state when leaving the page using Win button and resume on the same timestamp when navigating back?
  • how to properly change one HLS stream to another one?
  • how to dispose/unload the player when leaving the page?
Jun 18, 2014 at 9:11 AM
The simplest thing to do is probably to programmatically add and remove the StreamingMediaPlugin instead of letting the XAML handle it. You might also look at hacking the plugin to pass through your .mp4 streams.

As for the exceptions, phonesm uses cancellation tokens to stop downloads as fast as it can when playback is stopped (as part of a stream change, because someone hit "Stop", or as part of a seek), but a side effect of that is that one can get a number of "TaskCancelledException"s and "OperationCancelledException"s. Are you seeing exceptions other than those?

For saving state, I would suggest reading the current position and either remembering the last stream you requested or reading MediaElementWrapper's Source property.

It should be safe change streams at any time--during playback, while stopped, or during a seek--simply by setting the source URL. I have not done any serious testing of this since the phonesm-1.2.2 build.

The normal unload handler for the plugin should shut things down. If things are not stopped or disposed, the two things to watch out for are a thread that is used to communicate with MediaElement and a periodic timer that polls the playlist when playing live/dynamic playlists. Any download that is in progress should timeout shortly after playback stops.
Jun 18, 2014 at 2:24 PM
Hi, I've created simple sample for testing the suspend and resume scenario:

My scenarios:
  • playing video, pressing Win, navigating back to app - the video should resume playing where I left.
  • playing video, pausing it, pressing Win, navigating back to app - the video should resume paused where I left it.
My sample contains MediaPlayer with standard mp4 video and another player with StreamingMediaPlugin and sample HLS video.
On the Standard page I've implemented the suspending and resuming according to the Media Player Framework page.
  • when suspending I use deactivatedState = Player.GetMediaState();
  • when resuming I use Player.RestoreMediaState(deactivatedState);
    Unfortunately on the HLS page when I return to the app, I got empty player with disabled buttons. I can't even manually restart the playback or jump to the previous position.
Could you please look at it, if it's possible to fix the StreamingMediaPlugin to handle this really common scenario properly? Thanks
Jun 19, 2014 at 1:19 AM
I ran into a couple of exceptions when looking at your HLSPlayerTest.WP8 project that resulted in the changes in b2c4c6892eea. There may be more changes needed, but could you see if those changes help with your problem?

Jun 19, 2014 at 12:20 PM
Thanks, the latest version 29eff22d5f90 works much better when pausing and resuming streams, it works even on our test HLS-AES and Live HLS stream!
I've only reported one new bug here:
Jun 20, 2014 at 1:15 PM
Back to the original question, I was trying to implement single MediaPlayer capable playing both mp4 and m3u8 formats, but for no success yet.
Initially I've tried to remove/add the StreamingMediaPlugin programatically, but it was not working. Here's a sample how I tried to do it

Right now this is the most problematic part of our app, if you find a solution how to do it clearly, it will be much appretiated.
As a backup solution it could also work to have two idential MediaPlayers on top of each other, one for mp4 and one for m3u8 streams, and dynamically showing and hiding the proper player.
Jun 20, 2014 at 11:35 PM
Try this instead:
        public void Standard_OnClick(object sender, RoutedEventArgs e)

            var smp = player.Plugins.OfType<StreamingMediaPlugin>().FirstOrDefault();

            if (null != smp)


            player.Source = new Uri("");

        public void HLS_OnClick(object sender, RoutedEventArgs e)

            var smp = player.Plugins.OfType<StreamingMediaPlugin>().FirstOrDefault();

            if (null == smp)
                player.Plugins.Add(new StreamingMediaPlugin());


            player.Source = new Uri("");
I won't go further than saying, "it seems to work." You may want to follow up with the Player Framework folks.