如何翻转 MediaPlayer 视频
How to flip MediaPlayer video
我正在使用 MediaPlayer
UWP MediaPlayer
播放一些动画
我想水平翻转动画,有点像镜像。
有没有办法用 UWP 媒体播放器实现这个?
一个比较简单的解决方法是使用Projection函数将MediaPlayerElement
里面的MediaPlayerPresenter
翻转180°。
<Style TargetType="MediaPlayerElement" x:Key="FlipMediaPlayerStyle">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="MediaPlayerElement">
<Grid x:Name="LayoutRoot">
<Border Background="Transparent" />
<Image x:Name="PosterImage"
Visibility="Collapsed"
Source="{TemplateBinding PosterSource}"
Stretch="{TemplateBinding Stretch}" />
<MediaPlayerPresenter x:Name="MediaPlayerPresenter"
IsFullWindow="{TemplateBinding IsFullWindow}"
Stretch="{TemplateBinding Stretch}"
MediaPlayer="{TemplateBinding MediaPlayer}"
RenderTransformOrigin="0.5,0.5"
>
<MediaPlayerPresenter.Projection>
<PlaneProjection RotationX="180" />
</MediaPlayerPresenter.Projection>
<MediaPlayerPresenter.RenderTransform>
<ScaleTransform ScaleX="-1" ScaleY="-1" />
</MediaPlayerPresenter.RenderTransform>
</MediaPlayerPresenter>
<ContentPresenter x:Name="TransportControlsPresenter"
Visibility="{TemplateBinding AreTransportControlsEnabled}" />
<Grid x:Name="TimedTextSourcePresenter" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
用法
<MediaPlayerElement x:Name="MyMedia"
Source="your_media_url"
AreTransportControlsEnabled="True"
Style="{StaticResource FlipMediaPlayerStyle}"
/>
我正在使用 MediaPlayer
UWP MediaPlayer
我想水平翻转动画,有点像镜像。
有没有办法用 UWP 媒体播放器实现这个?
一个比较简单的解决方法是使用Projection函数将MediaPlayerElement
里面的MediaPlayerPresenter
翻转180°。
<Style TargetType="MediaPlayerElement" x:Key="FlipMediaPlayerStyle">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="MediaPlayerElement">
<Grid x:Name="LayoutRoot">
<Border Background="Transparent" />
<Image x:Name="PosterImage"
Visibility="Collapsed"
Source="{TemplateBinding PosterSource}"
Stretch="{TemplateBinding Stretch}" />
<MediaPlayerPresenter x:Name="MediaPlayerPresenter"
IsFullWindow="{TemplateBinding IsFullWindow}"
Stretch="{TemplateBinding Stretch}"
MediaPlayer="{TemplateBinding MediaPlayer}"
RenderTransformOrigin="0.5,0.5"
>
<MediaPlayerPresenter.Projection>
<PlaneProjection RotationX="180" />
</MediaPlayerPresenter.Projection>
<MediaPlayerPresenter.RenderTransform>
<ScaleTransform ScaleX="-1" ScaleY="-1" />
</MediaPlayerPresenter.RenderTransform>
</MediaPlayerPresenter>
<ContentPresenter x:Name="TransportControlsPresenter"
Visibility="{TemplateBinding AreTransportControlsEnabled}" />
<Grid x:Name="TimedTextSourcePresenter" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
用法
<MediaPlayerElement x:Name="MyMedia"
Source="your_media_url"
AreTransportControlsEnabled="True"
Style="{StaticResource FlipMediaPlayerStyle}"
/>