【问题标题】:Exiting full screen with Xamarin Forms MediaElement calls MainPage OnAppearing()使用 Xamarin Forms MediaElement 调用 MainPage OnAppearing() 退出全屏
【发布时间】:2020-04-08 19:48:54
【问题描述】:

我已将 VideoPlayer 实现到我的 Xamarin Forms 4.5 应用程序中,如本文档中所述: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/video-player/

播放 HLS 视频效果很好。但是,当我在 iOS 上退出全屏模式时,视频的声音会继续在后台播放,并且应用程序会导航回我的 MasterDetailsPage 的根目录。

当我返回打开视频播放器的页面时,页面应用冻结。

如果我在不进入视频播放器的全屏模式的情况下播放视频,一切正常。

我使用的是 iOS SDK 13.4。

更新

我切换到新的 Xamarin Forms MediaElement (https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/mediaelement)。

现在,当我退出全屏时,整个应用程序都会崩溃。

进入全屏时收到此警告:

 *** Warning: <AVPlayerViewController: 0x7fcfe36bda00> is trying to enter full screen, but is not in its view's window's view controller hierarchy. This results in undefined behavior.

我在退出全屏时收到此警告:

 *** Warning: <AVPlayerViewController: 0x7fcfe36bda00> is trying to exit full screen, but is not in its view's window's view controller hierarchy. This results in undefined behavior.

XAML 代码:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MyApp.Views.VideoPage">
    <MediaElement x:Name="videoPlayer" ShowsPlaybackControls="True" />
</ContentPage>

C#代码:

using System.Collections.Generic;
using Xamarin.Forms;

namespace MyApp.Views
{
    public partial class VideoPage : ContentPage
    {
        public VideoPage(Video videoItem)
        {
            InitializeComponent();

            videoPlayer.Source = videoItem.Url;
        }
    }
}

更新 #2:

我发现了问题,但我没有解决办法。退出VideoPlayer全屏模式时,调用MainPage的OnAppearing()方法。

更新 #3:

代码示例和如何重现可以在我的 GitHub 问题中找到: https://github.com/xamarin/Xamarin.Forms/issues/10169

【问题讨论】:

  • 在方法OnDisappearing中将palyer设置为null。
  • 这样做会有效地阻止 videoPlayer 在后台播放。我仍然有我的应用程序在退出全屏后返回到根 MasterDetails 页面而不是停留在 VideoPage 上的问题。
  • 你最好分享一个样本,这样我就可以在我身边测试它。您的代码无法提供足够的信息来找出原因..
  • 在更新 3 中添加了代码示例的链接。
  • 因为你把标签页放在了主详情页。你最好使用 Shell。

标签: ios xamarin.forms fullscreen mediaelement video-player


【解决方案1】:

使用 TabPage 应用将我的 MasterDetailsPage 升级到新的 Xamarin.Forms Shell 解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-19
    • 1970-01-01
    • 2021-02-20
    • 2021-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多