XamarinMediaManager icon indicating copy to clipboard operation
XamarinMediaManager copied to clipboard

Xamairn.Forms iOS: Switching tabs would make the player black .

Open ahmad-crossplatform opened this issue 5 years ago • 7 comments

🐛 Bug Report

I have an app with multiple tabs one of them has the VideoView that plays the sample video automatically , when i switch to the next tab i can still hear the video playing . However, when i switch back to the video tab , the video is still playing (i can hear it) but I can see only black box instead of the actual video .

I think it has to do with what this link says https://stackoverflow.com/questions/21737017/avplayerlayer-blank-after-entering-background-while-being-in-a-hidden-controller/42822384#42822384

Note: This works on Android

Expected behavior

You can see the video when you switch back between the tabs

Reproduction steps

I have uploaded a sample project.

Configuration

Version: 0.8.9 MediaManagerSample.zip

Platform:

  • [x] :iphone: iOS
  • [ ] :robot: Android
  • [ ] :checkered_flag: WPF
  • [ ] :earth_americas: UWP
  • [ ] :apple: MacOS
  • [ ] :tv: tvOS
  • [x] :monkey: Xamarin.Forms

ahmad-crossplatform avatar Sep 20 '19 19:09 ahmad-crossplatform

Yes i noticed this issue too. It only happens on Forms, with iOS. The problem is that Forms doesn't pass on the viewcontroller events, which i use to hook up the videoview.

For now you can work around it by setting the videoview manually: https://github.com/martijn00/XamarinMediaManager#add-video-player-to-the-ui

martijn00 avatar Sep 24 '19 18:09 martijn00

Ok two questions :

  1. What is the difference between VideoView and VideoPlayer ? and why they are two different things ?
  2. regarding your workaround, if I have a Xamarin.Forms , how i would apply it ? is it kind of dependency service ?

ahmad-crossplatform avatar Sep 24 '19 18:09 ahmad-crossplatform

  1. VideoView is a custom view within MediaManager to show video. It adds some extra functionality so crossplatform works better. VideoPlayer is the native platform player that is used to playback the video.

  2. This is where the view is added in Forms: https://github.com/martijn00/XamarinMediaManager/blob/develop/MediaManager.Forms/Platforms/Ios/VideoViewRenderer.cs

This is where the problem is: https://github.com/martijn00/XamarinMediaManager/blob/develop/MediaManager/Platforms/Ios/Video/VideoView.cs#L35

Superview?.NextResponder as UIViewController is not a UIViewController but a UIView in Forms. Somehow i should be able to get a hold of the UIViewController and pass that, and then it would be fixed.

martijn00 avatar Sep 24 '19 18:09 martijn00

I'm running into this too... I'm also getting a hard crash with the video player... I'm trying to diagnosis it, but it straight up kills the app. I'm playing some music, then switch to playing a video and the app just dies. Only on iOS so I'm thinking there could be a relation.

I added the view render for iOS like shown in step 2 and also add MediaManager.CrossMediaManager.Current.MediaPlayer.VideoView = _videoView; to assign the view, and set auto-attach to false but it doesn't seem to be making a difference, the screen is still black... it's quite possible I'm missing something.

However, in my use case, I have an grid and in 1 row I have an image view and the VideoView and only 1 visible at a time... so when a song is playing the album art is shown and the video player is hidden and when a video is played, the opposite is in effect.

Thanks, Rich

richp582 avatar Oct 06 '19 22:10 richp582

@martijn00 getting same issue even video view added manually to mediamanager. Any help on this? Thanks in advance

SatyaRamprasad avatar Oct 31 '19 12:10 SatyaRamprasad

I'm also having this issue on Android. It seems that it's only possible to do CrossMediaManager.Current.MediaPlayer.VideoView = _videoView; Before SetNativeControl() on Android.

After that it seems like you cannot detach it or attach a different VideoView.

LittleBoxOfChicken avatar Feb 19 '21 10:02 LittleBoxOfChicken

make sure you have your videoview in an content video, then the video player will still visible

innomotionmedia avatar Aug 10 '21 09:08 innomotionmedia