如何更改mediaelement以在Windows Phone 8.1上以横向模式纵向缩放和全屏缩放?
问题描述:
当手机在横向模式下旋转时,我很难尝试将<mediaelement />
自动更改为全屏。现在,当我点击右下按钮时,视频会播放全屏,当我点击它时缩放到全屏,但我不想那样。在纵向模式下,我试图根据手机屏幕的宽度来设置<mediaelement />
,我不确定如何操作或者我在布局问题上做错了什么。如何更改mediaelement以在Windows Phone 8.1上以横向模式纵向缩放和全屏缩放?
这里的布局我在XAML:
MainPage.xaml中:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel Width="Auto" Height="250" Background="Green" Orientation="Horizontal" VerticalAlignment="Top">
<MediaElement x:Name="media"
Source="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
AutoPlay="True"
AreTransportControlsEnabled="True"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Stretch="UniformToFill"
Width="Auto"
Height="Auto"
/>
</StackPanel>
</Grid>
方向更改更新的代码:
我调试这个方法,它会经过当手机处于横向模式时的if语句,但是当我纵向倾斜手机时,它不会识别任何内容。当手机放入肖像时,我错过了什么来识别肖像事件处理程序? MediaElement似乎卡在IsFullWindow = true
中,并且从不再检查orientationchanged事件方法变为IsFullWindow = false
。
void MainPage_OrientationChanged(DisplayInformation sender, object args)
{
var orientation = DisplayInformation.GetForCurrentView().CurrentOrientation; // get the current orientation of the display
if (orientation == DisplayOrientations.Landscape || orientation == DisplayOrientations.LandscapeFlipped) // if the orientation is landscape...
{
media.IsFullWindow = true; // puts the media element in full screen while in landscape
}
else //if (orientation == DisplayOrientations.Portrait || orientation == DisplayOrientations.PortraitFlipped)
{
media.IsFullWindow = false; // puts the media element out of full screen in portrait
//media.Width = Window.Current.Bounds.Width; // set bounds of video width to width of screen
}
}
答
一个简单的解决将是设置IsFullWindow="True"
在XAML媒体元素属性与该媒体元素在全屏幕将发挥不管方向。(虽然它总是会在横向模式下)。您还可以根据您的要求,使用C#将媒体元素属性IsFullWindow
设置为true
发布更新了如何在手机放入肖像时识别肖像事件处理程序? MediaElement似乎停留在IsFullWIndow = true并且从不再检查orientationchanged事件方法。 – TheAmazingKnight
正如我所说,无论方向如何,FullWindow = true都将始终处于横向模式。既然你不想让它现在最大化。您需要指定改变方向的媒体元素的位置,然后设置其来源。现在,mediaOpened事件内部指定您希望播放器停止全屏模式,还是从之前播放的位置恢复它。 – Jerin