1
votes

I have implemented the VideoPlayer into my Xamarin Forms 4.5 app as described in this documentation: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/video-player/

Playing HLS videos is working nicely. However, when I exit from the full-screen mode on iOS, the sound of the video continues to play in the background and the app navigates back to the root of my MasterDetailsPage.

When I return to the page that opens the video player, the page app freezes.

Everything behaves normally if I play the videos without entering the video player's full-screen mode.

I'm using iOS SDK 13.4.

Update

I switched to the new Xamarin Forms MediaElement (https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/mediaelement).

Now the entire app crashes when I exit fullscreen.

I receive this warning when entering fullscreen:

 *** 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.

I receive this warning when exiting fullscreen:

 *** 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 Code:

<?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# Code:

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

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

            videoPlayer.Source = videoItem.Url;
        }
    }
}

Update #2:

I figured out the issue, but I do not have a fix. When exiting the VideoPlayer fullscreen mode, the OnAppearing() method of the MainPage is called.

Update #3:

Code sample and how to reproduce can be found in my GitHub issue: https://github.com/xamarin/Xamarin.Forms/issues/10169

1
Set the palyer as null in method OnDisappearing . - Lucas Zhang
Doing this effectively kills the videoPlayer from playing in the background. I still have the issue that my app returns to the root MasterDetails Page after exiting full screen instead of just staying on the VideoPage. - fnllc
You could better share a sample so that I can test it on my side . Your code could not provide enough info to find out the cause .. - Lucas Zhang
Added link to code sample in Update 3. - fnllc
Because you put the tabbed page in the master detail page . You could better use Shell . - Lucas Zhang

1 Answers

0
votes

Upgrading my MasterDetailsPage with TabPage app to the new Xamarin.Forms Shell fixed this issue.