在 Android 和较旧的 IOS 版本上一切正常,但在使用 IOS 版本 13.5 时,切换到全屏时视频会崩溃。该应用程序不会崩溃,也不例外,我可以通过退出全屏并再次按播放来重新启动视频。在 iPhoneSimulator 和真实设备上使用不同的设备和 IOS 版本进行了测试。还尝试隐藏导航栏并尝试不同的方向。
// ViewModel
private async void PlayVideo(object parameter)
{
PageManager.NavigateTo(typeof(VideoViewerPage));
CrossMediaManager.Current.MediaPlayer.VideoAspect = MediaManager.Video.VideoAspectMode.AspectFit;
CrossMediaManager.Current.MediaPlayer.ShowPlaybackControls = true;
if (Device.RuntimePlatform == Device.iOS)
{
await CrossMediaManager.Current.PlayFromResource(parameter.ToString());
}
else if(Device.RuntimePlatform == Device.Android)
{
Stream stream = DependencyService.Get<IReadFile>().Open(parameter.ToString());
await CrossMediaManager.Current.Play(stream, "Video");
}
}
// View
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mm="clr-namespace:MediaManager.Forms;assembly=MediaManager.Forms"
mc:Ignorable="d"
x:Class="SharedProject.Views.VideoViewerPage"
NavigationPage.HasNavigationBar="True">
<mm:VideoView VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"/>
</ContentPage>
// Codebehind of View
public VideoViewerPage()
{
InitializeComponent();
if (Device.RuntimePlatform == Device.Android)
{
NavigationPage.SetHasNavigationBar(this, false);
}
}
protected override void OnAppearing()
{
MessagingCenter.Send(this, "allowLandScapePortrait");
base.OnAppearing();
}
protected override void OnDisappearing()
{
MediaManager.CrossMediaManager.Current.Stop();
MessagingCenter.Send(this, "preventLandScape");
base.OnDisappearing();
}