问题
I added a MediaPlayerElement to my XAML as follow:
<MediaPlayerElement x:Name="EmbeddedPlayer" AreTransportControlsEnabled="True" HorizontalAlignment="Stretch">
<MediaPlayerElement.TransportControls>
<MediaTransportControls IsSkipBackwardButtonVisible="True" IsSkipBackwardEnabled="True" IsSkipForwardButtonVisible="True" IsSkipForwardEnabled="True"/>
</MediaPlayerElement.TransportControls>
</MediaPlayerElement>
The problem is that the Fullscreen button provided by MediaTransportControls does NOT hide the navigation bar (the region containing the back, start and search buttons) on phone while I expect it to, just like the system "Movies & TV" app. It only hides the status bar!? (It works on desktop.)
Is there a secret code to allow the navigation bar to be hidden or is it just not possible with 3rd party app? I tried ApplicationView.TryEnterFullScreenMode in my MainPage on Windows 10 Mobile 14393.693 but just like above, the navigation bar is not hidden (only the status bar does).
回答1:
The "Movie & TV" app doesn't hide the navigation bar by default. The reason for why you see it hide the navigation bar by default is that the player is in full window model by default. Double tapped the player of "Movie & TV" app, the player will exit the full window mode and the bar will show.
So if you want have same effects like "Movie & TV" app, you need to set the IsFullWindow property of MediaPlayerElement like follows:
<MediaPlayerElement x:Name="EmbeddedPlayer" AreTransportControlsEnabled="True" HorizontalAlignment="Stretch" IsDoubleTapEnabled="True" IsFullWindow="True" >
<MediaPlayerElement.TransportControls>
<MediaTransportControls />
</MediaPlayerElement.TransportControls>
</MediaPlayerElement>
Also you can define a DoubleTapped event for the MediaPlayerElement that double tap will exit the full window mode. Code as follows and now it has same effects as the "Movie & TV" done.
public MainPage()
{
this.InitializeComponent();
EmbeddedPlayer.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/New2.mp4"));
EmbeddedPlayer.DoubleTapped += EmbeddedPlayer_DoubleTapped;
}
private void EmbeddedPlayer_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
var view = ApplicationView.GetForCurrentView();
if (view.IsFullScreenMode)
view.ExitFullScreenMode();
else
view.TryEnterFullScreenMode();
}
回答2:
After finding my answer for another problem on casting video to TV, I found out that one MUST NOT use the recommended MediaPlayerElement but the deprecated MediaElement for the navigation bar to be hidden properly.
来源:https://stackoverflow.com/questions/41644934/mediaplayerelement-fullscreen-button-does-not-hide-navigation-bar