簡體   English   中英

如何在Windows Phone 8.1上更改媒體元素以在縱向和橫向模式下以縱向和全屏縮放?

[英]How to change mediaelement to scale in portrait and fullscreen in landscape mode on Windows Phone 8.1?

當手機在橫向模式下旋轉時,嘗試將<mediaelement />自動更改為全屏時遇到困難。 現在,當我點擊右下角的按鈕時,該視頻將以全屏播放,但我不希望這樣做。 在縱向模式下,我試圖根據電話屏幕的寬度使<mediaelement />適合,但我不確定該怎么做或我在布局問題上做錯了什么。

這是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並且從不再檢查是否IsFullWindow = true了定向方法來變為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
    }
}

一個簡單的解決方法是在XAML的media元素屬性中設置IsFullWindow="True" ,無論方向如何,media元素都將在全屏模式下播放。(盡管它始終處於橫向模式)。 您還可以根據需要使用C#將媒體元素屬性IsFullWindow為true。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM