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

can't stop reloading those dynamic playlists when we stop playback.

May 3, 2013 at 3:26 PM
Hello Henric!

Great work! thank you very much.

i found a bug, when we stop or close player view.
PlaylistSegmentManager::MoveNextAsync already running....

can you give me some help?

Thanks again :)
Coordinator
May 3, 2013 at 3:52 PM
Thanks.

Which changeset are you using?

I ran into that "stop" problem myself yesterday. A386b6f2e166 changed the way the cancellation token is used when playback is stopped. That should help, if you aren't using it already.

I brought in the Microsoft.Net.Http NuGet package yesterday (changeset 1f658bfbf4b5) since the HttpClient's API is more cancellation friendly. However, I have not yet had a chance to use it anywhere other than in M3U8ParserPlatformExtensions.
May 3, 2013 at 4:16 PM
Edited May 3, 2013 at 4:18 PM
thank you reply.


I using 9d77136ddf54.

some test code like this(SamplePlayer.WP8).
MainPage.xaml 
<phone:PhoneApplicationPage x:Class="SamplePlayer.WP8.MainPage"
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                            xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                            xmlns:mmppf="clr-namespace:Microsoft.PlayerFramework;assembly=Microsoft.PlayerFramework"
                            xmlns:smmedia="clr-namespace:SM.Media.MediaPlayer;assembly=SM.Media.MediaPlayer.WP8"
                            mc:Ignorable="d"
                            FontFamily="{StaticResource PhoneFontFamilyNormal}"
                            FontSize="{StaticResource PhoneFontSizeNormal}"
                            Foreground="{StaticResource PhoneForegroundBrush}"
                            SupportedOrientations="Landscape"
                            Orientation="Landscape"
                            shell:SystemTray.IsVisible="False">
    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot"
          Background="Transparent">
        <Button Content="Button" HorizontalAlignment="Left" Height="88" Margin="43,210,0,0" VerticalAlignment="Top" Width="185" Click="Button_Click_1"/>
    </Grid>
</phone:
MainPage.xaml.cs
public MainPage()
    {
        InitializeComponent();

        // Sample code to localize the ApplicationBar
        //BuildLocalizedApplicationBar();
    }

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {

        String param = String.Format("/Player.xaml");

        NavigationService.Navigate(new Uri(param, UriKind.Relative));
    }
Player.xaml 
<phone:PhoneApplicationPage
    x:Class="SamplePlayer.WP8.Player"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                            xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                            xmlns:mmppf="clr-namespace:Microsoft.PlayerFramework;assembly=Microsoft.PlayerFramework"
                            xmlns:smmedia="clr-namespace:SM.Media.MediaPlayer;assembly=SM.Media.MediaPlayer.WP8"
                            mc:Ignorable="d"
                            FontFamily="{StaticResource PhoneFontFamilyNormal}"
                            FontSize="{StaticResource PhoneFontSizeNormal}"
                            Foreground="{StaticResource PhoneForegroundBrush}"
                            SupportedOrientations="Landscape"
                            Orientation="Landscape"
                            shell:SystemTray.IsVisible="False">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot"
          Background="Transparent">
        <mmppf:MediaPlayer Source="http://www.nasa.gov/multimedia/nasatv/NTV-Public-IPS.m3u8">
            <mmppf:MediaPlayer.Plugins>
                <smmedia:StreamingMediaPlugin />
            </mmppf:MediaPlayer.Plugins>
        </mmppf:MediaPlayer>
    </Grid>

</phone:PhoneApplicationPage>
when close player.xaml,but player.xaml can't exit close thread.

after close player.xaml, the log information like:

PlaylistSegmentManager.PlaylistExpiration (2013/5/3 23:15:16 +08:00)
PlaylistSegmentManager.PlaylistExpiration is starting ReadSubList (2013/5/3 23:15:16 +08:00)
PlaylistSegmentManager.ReadSubList (2013/5/3 23:15:16 +08:00)
PlaylistSegmentManager.ReadSubList: playlist http://nasahd-i.akamaihd.net/hls/live/203739/NASATV1_iOS_HD/Edge.m3u8 loaded with 15 entries in 00:00:00.5682705. index: 10 dynamic: True expires: 00:00:32 (2013/5/3 23:15:16 +08:00)
线程 0xb4c 已退出,返回值为 259 (0x103)。
线程 0x1f0 已退出,返回值为 259 (0x103)。
线程 0xf54 已退出,返回值为 259 (0x103)。
线程 0x7b0 已退出,返回值为 259 (0x103)。
PlaylistSegmentManager.PlaylistExpiration (2013/5/3 23:15:48 +08:00)
PlaylistSegmentManager.PlaylistExpiration is starting ReadSubList (2013/5/3 23:15:48 +08:00)
PlaylistSegmentManager.ReadSubList (2013/5/3 23:15:49 +08:00)
PlaylistSegmentManager.ReadSubList: playlist http://nasahd-i.akamaihd.net/hls/live/203739/NASATV1_iOS_HD/Edge.m3u8 loaded with 19 entries in 00:00:00.2964564. index: 14 dynamic: True expires: 00:00:32 (2013/5/3 23:15:49 +08:00)
Coordinator
May 3, 2013 at 6:13 PM
The IMediaPlugin/IMediaElement implementations in SM.MediaPlayer.WP8 are incomplete. Compare what it does to what HlsView/HlsView.WP8 does in MainPage.xml.cs.

I think it is really important that "_tsMediaManager.Close();" gets called ("_tsMediaManger" can be found in MediaElementWrapper).

The HlsView application does this when the media has failed, when it has closed, and also on the page's OnNavigatedFrom (where it also detaches the MediaElement from the visual tree; this is important on WP7, but I'm not sure if it matters on WP8).

For a reference implementation, grab the player framework's source code and take a look at the AdaptivePlugin implementation (in the Microsoft.WP8.PlayerFramework.SL.Adaptive project).

I haven't had a chance to try any of the below...

Make some changes to StreamingMediaPlugin along the lines of the following,
        MediaElementWrapper _mediaElement;

        public void Load()
        {
            MediaPlayer.MediaClosed += MediaPlayer_MediaClosed;
        }

        void MediaPlayer_MediaClosed(object sender, RoutedEventArgs e)
        {
            if (null == _mediaElement)
                return;

            _mediaElement.Close();
        }

        public void Update(IMediaSource mediaSource)
        {  }

        public void Unload()
        {
            MediaPlayer.MediaClosed -= MediaPlayer_MediaClosed;

            if (null != _mediaElement)
            {
                _mediaElement.Cleanup();
            }
        }
and add this to MediaElementWrapper:
        public void Close()
        {
            if (null == _tsMediaManager)
                return;

            _tsMediaManager.Close();
        }

        public void Cleanup()
        {
            Close();

            if (null != _mediaElementManager)
                _mediaElementManager.Close()
                                    .Wait();
        }
and it should be a start. I'm pretty sure there are some other events that also need to get wired up to make sure that MediaElementWrapper's Close() gets called when it should.

I'll probably get a chance to look at this in more depth in a few days.
May 4, 2013 at 1:34 PM
thank you very much for your help.