Remove player from visual tree and add it again

Jan 2, 2011 at 2:30 PM

If I play a movie (smooth streaming) and remove the SMFPlayer from the visual tree in the middle of the movie, and than add it to the visual tree again, the screen is black, and the movie won't play. If I select a new video from the playlist and then press play it works again. Why? I need to remove the player from the visual tree when the user enters fullscreen mode, and attach it to another panel which alows it to fill the entire screen, but then the movie won't play before the user switches playlist item. What can I do to fix this?

Apr 26, 2011 at 4:45 PM

I have the same problem in my app.

Currently, I'm using a very poor workaround: removing and re-adding PlaylistItem.

Code:

UIElement backup = null;

        private void Player_FullScreenChanged(object sender, EventArgs e)
        {
            var root = (App.Current.RootVisual as MainPage).LayoutRoot;

            if (Player.IsFullScreen)
            {
                PlaylistItem item = Player.CurrentPlaylistItem;
                Player.Playlist.Clear();

                PlayerContainer.Child = null;
                backup = root.Child;
                root.Child = Player;

                Player.Playlist.Add(item);
                Player.Play();

                this.Visibility = Visibility.Collapsed;
            }
            else
            {
                PlaylistItem item = Player.CurrentPlaylistItem;
                Player.Playlist.Clear();

                root.Child = backup;
                PlayerContainer.Child = Player;

                Player.Playlist.Add(item);
                Player.Play();

                this.Visibility = Visibility.Visible;
            }
        }

Player is a SMFPlayer, my root contents are both Border (else it would be root.Children.Clear() or root.Children.Add(Player) for instance).

 

I would be very happy to have a better way. I will try to avoid the visual tree modification.