Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blank YouTubePlayerView after return from 2 hours in background #4

Closed
jackpal opened this issue Oct 17, 2021 · 7 comments
Closed

Blank YouTubePlayerView after return from 2 hours in background #4

jackpal opened this issue Oct 17, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@jackpal
Copy link

jackpal commented Oct 17, 2021

This bug is similar to my previous bug, but it happens on iPhones as well, not just an iPad in portrait mode. So I think it's more serious.

I've seen this bug in my own app that uses YouTubePlayerKit, but I figure you'd prefer a repro that uses your own example app.

I tried a bunch of things to get around the issue, but as you can imagine it takes a while to run each test. I haven't found a work-around that I am sure works yet.

configuration
Xcode 15, iOS 15.0.2, YouTubePlayerKit 1.1.1
Repros on iPad 2018, iPad Mini 2021, iPhone 13 Pro

Repro steps:
Build and install WWDCKeynote app on iPhone
Run app
Lock screen
Wait a couple of hours (Sorry I haven't nailed down the minimum time for this repro. Waiting overnight has always reproduced the issue, I think two hours has also always reproduced the issue.. 30 minutes is usually not enough.)
Unlock screen

Expected:
See WWDC video

Actual:
Blank view for the Video, need to force-quit the app to get it to work again

I can also reproduce this by putting the WWDC app into the background, and doing "stuff" with my phone, such as playing videos in the YouTube app, surfing the web in Safari, and then switching back to the app. But it doesn't always reproduce this way, so it's harder to use it as a test case.

@jackpal jackpal changed the title WWDCKeynote - blank screen after return from 2 hours in background Blank YouTubePlayerView after return from 2 hours in background Oct 17, 2021
@SvenTiigi SvenTiigi added the bug Something isn't working label Oct 17, 2021
@SvenTiigi
Copy link
Owner

Hi @jackpal,

Thanks for your detailed bug report 👍

This seems like a very strange behaviour and I will try to check if I can reproduce this bug on my side too.

But I think it might be the same scenario as in your last issue where no visible error is reported in the Xcode Debug Console, Simulator Console and JavaScript Console via Safari Developer Tools.

Of course a possible solution would be to reload the entire YouTubePlayer when a UIApplication.didBecomeActiveNotification gets posted by the NotificationCenter which is not really elegant/suitable.

@jackpal
Copy link
Author

jackpal commented Oct 17, 2021

I tried that (by updating the player configuration referrer), and it "may" have worked. I need to do some overnight tests to be sure.

In past tests I noticed that when the app gets into that state, the YouTubePlayer.State is "ready" and the YouTubePlayer.PlaybackState is "cued". So maybe I can use a timer to determine that the PlaybackState is stuck in "cued" and then only reset the player when stuck mode is detected.

I also tried registering for some of the more obscure error callbacks like WKNavigationDelegate webViewWebContentProcessDidTerminate, but as far as I can tell that's not being called in this situation.

@jackpal
Copy link
Author

jackpal commented Oct 18, 2021

Follow-up - the "always reload on didBecomeActive" approach seems to be working. Thanks for the suggestion!

@SvenTiigi
Copy link
Owner

SvenTiigi commented Oct 18, 2021

Additionally, I have just pushed a feature branch feature/bug-fix-issue-4 which removes the usage of the WKUserContentController that has been used to retrieve JavaScript Events.

Apple declares that the WKUserContentController is the preferred way of receiving any JavaScript events from a WKWebView. But I found many threads in the Apple developer forum that the WKUserContentController sometimes causes memory leaks.

Therefore I switched back the way of receiving JavaScript events in the same way as the official youtube-ios-player-helper from YouTube does via updating the window.location.href and cancelling the navigation inside the WKNavigationDelegate.

Maybe this change could potentially resolve this issue 🤔

@SvenTiigi
Copy link
Owner

The feature branch bug-fix-issue-4 has been merged into the develop branch and is now included within the latest release 1.1.3

As far as my own debugging I haven't experienced a blank YouTubePlayerView even after long background time so I'm closing this issue for now.

Please feel free to re-open the issue at anytime ✌️

@jackpal
Copy link
Author

jackpal commented Nov 5, 2021

Unfortunately I can still reproduce the black screen bug using 1.1.3.

If you want to see if you can repro it too, clone the https://github.com/jackpal/AmahTV project and sync to

6a4ab4c96cc3f552017b0cea09c3569862c03506

Run the app, pick any channel, switch to some other app, wait a day, and then rerun the app.

It's not a huge deal, as the work-around still works.

Feel free to close the bug as "can't repro"... or "has work around".

@SvenTiigi
Copy link
Owner

Seems like there is some internal stuff going on inside the WKWebView or a bug inside the YouTubePlayer iFrame API which causes this very strange black screen scenario 😅

I will keep this issue closed for now and maybe try to find a fix for this issue in the near future 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants