Xamarin.Forms CrossMediaManaer-切换到全屏模式时视频崩溃

时间:2020-06-22 10:12:02

标签: ios xamarin.forms fullscreen plugin.media.crossmedia

一切都适用于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();
        }

0 个答案:

没有答案