Video is ALWAYS on top
BACKGROUND: My use-case for a video player is to play a "cutscene" video prior to showing the "rest" of my view. To do this, I use two Grids and a storyboard system that controls the opacity of the two grids. In my first grid I define the video container, and in the second grid I set the rest of my content. Something like this:
<UserControl>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vlc="clr-namespace:LibVLCSharp.WPF;assembly=LibVLCSharp.WPF"
xmlns:Mvvm="clr-namespace:Microsoft.Practices.Prism.Mvvm;assembly=Microsoft.Practices.Prism.Mvvm.Desktop"
Mvvm:ViewModelLocator.AutoWireViewModel="True"
Width="800"
Height="600">
<UserControl.Resources>
<ResourceDictionary>
<Storyboard x:key="Storyboard1">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="videoGrid" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="contentGrid" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ResourceDictionary>
<UserControl.Resources>
<Grid x:Name="videoGrid" Opacity="1" Margin="0,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<vlc:VideoView Grid.Column="0" Grid.Row="0" x:Name="vlcPlayer"/>
</Grid>
<Grid x:Name="contentGrid" Opacity="0" Margin="0,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- A bunch of stuff with different content than a video -->
</Grid>
</UserControl>
Then, in my code behind I set the EndReached
and EncounteredError
events to functions, and in those functions they do something like this:
private void vlcPlayer_MediaEnded(object sender, EventArgs e)
{
this.Dispatcher.Invoke(() =>
{
Storyboard sb1 = (Storyboard)TryFindResource("Storyboard1");
if (sb1 != null)
sb1.Begin();
});
}
}
I find that everything works as it's supposed to, EXCEPT the VLC video object doesn't fade away - it stubbornly stays visible and won't give visibility up even to what's defined in front of it.
Is there any way to make the video "invisible"?
I really DO NOT want to have a view just dedicated to playing a video, that would be so frustrating.
Any suggestions?
-Danny