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

onReady never called when enter and exit activity quickly #830

Closed
ducdat-ptit opened this issue Mar 24, 2022 · 21 comments
Closed

onReady never called when enter and exit activity quickly #830

ducdat-ptit opened this issue Mar 24, 2022 · 21 comments
Labels

Comments

@ducdat-ptit
Copy link

Screen_Recording_20220324-115229_ayp.API.mp4
@ducdat-ptit ducdat-ptit changed the title onReady never called if enter and exit activity quickly onReady never called when enter and exit activity quickly Mar 24, 2022
@PierfrancescoSoffritti
Copy link
Owner

did you make any change to the code?

@ducdat-ptit
Copy link
Author

did you make any change to the code?

No. I didn't. The video is from sample apk: (core v11.0.1.apk

@nerooke
Copy link

nerooke commented Apr 1, 2022

did you make any change to the code?

I have same issue, player do not ready in this case.

@PierfrancescoSoffritti
Copy link
Owner

Which device are you using?

@ducdat-ptit
Copy link
Author

I checked on Samsung s10 (api 31), Samsung note10 (api 31), Pixel 4 (api 30), Xiaomi redmi note 8 (api 30)

@PierfrancescoSoffritti
Copy link
Owner

I just tried and everything works fine for me. Maybe it's something local to your build?

@ralexey
Copy link

ralexey commented Apr 4, 2022

@PierfrancescoSoffritti
I tried to use your library at the project for my client and i got the same behaviour.
Tested on several devices with Android 12 (Pixel 3a XL in my case)
I can open/close 2-3 time the activity and it shows the YT video, but it shows the black screen on the next time and doesn't call the onReady. But if i close/open the activity again - it works fine.

I used the manual initialisation, set the lifecycle and manual load or cue the YT video id.

@PierfrancescoSoffritti
Copy link
Owner

PierfrancescoSoffritti commented Apr 4, 2022

I was able to replicate the issue now. I initially misunderstood what this bug is about.

How to replicated:

  • In the core sample app
  • Open "Simple Example" and quickly close the Activity by navigating back
  • Repeat for 2/3 times
  • Eventually player shows black screen

This seems to be fixed by closing the Activity and opening it again.

This issue does not happen unless the user moves between activities very quickly.

I don't know exactly what's going on, but i suspect something is not cleaned up/starting the webview has some side-effect that persists between different activities.

@Wayne-Wang-Wayne
Copy link

I got the same issue here, what is the fix QQ?

@Fangzsx
Copy link

Fangzsx commented Apr 12, 2022

Faced the same issue. Any workaround to fix this?

@minseokchoi
Copy link

minseokchoi commented Apr 15, 2022

I have same issue
chrome app 98.0.4758.101 No problem
chrome app 100.0.4896.88 there is a problem

This is a problem caused by the latest Chrome update.
Waiting time varies depending on the model 1 to 10 seconds

@PierfrancescoSoffritti
Any workaround to fix this?

@Fangzsx
Copy link

Fangzsx commented Apr 15, 2022

I know this seems messy but I tried overriding the onError. I called the youtubePlayer.loadVideo again and insert the responding videoID. If the youtube player display playback error, if you click the video, loadvideo will be called once again hence, loading the video once more.

@TheBeastLT
Copy link

TheBeastLT commented May 24, 2022

I've encountered the same issue, where a video will not call the ready callback or start to play if it was initialized in a quick succession after another one was destroyed. I noticed from logs that if some Audio resources are not released before playing the next video, I'll get this behaviour. If I see the audio resources released in the logs and try to play the video, it will play alright.
These are the logs that I need to wait for before starting another video:

D/AAudio: AAudioStream_close(s#8) called ---------------
D/AAudioStream: setState(s#8) from 10 to 11
D/AAudioStream: setState(s#8) from 11 to 12
    ~AudioStream(s#8) mPlayerBase strongCount = 2
D/AAudio: AAudioStream_close(s#8) returned 0 ---------

@brain-deaf
Copy link

Also encountering this issue when replacing the fragment with a new one. The YouTubePlayerCallback is never called.

@robm92
Copy link

robm92 commented Jul 14, 2022

Same issue here, when contained in an AndroidView for Jetpack Compose, recomposing often causes a blank screen on the player.

@flauschtrud
Copy link
Contributor

I found something! (I'm also having the blank webview issue while using Jetpack Compose, it happens after a bunch of recompositions)

With a very old webview version everything is fine (I had Chrome deactivated on my device and after reactivating it a very old version was installed):
2022-07-15 10:12:05.861 12047-12047/com.flauschcode.omcast I/WebViewFactory: Loading com.google.android.webview version 79.0.3945.116 (code 394511605)

I did not experience the blank webview issue in this case.

When the Chrome app is deactivated and an up-to-date version of Android System WebView is used there's a NoClassDefFoundError just after loading the app (and webviews might not be loaded properly):

2022-07-15 10:38:25.354 11975-11975/com.flauschcode.omcast I/WebViewFactory: Loading com.google.android.webview version 103.0.5060.71 (code 506007103)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas: Rejecting re-init on previously-failed class java.lang.Class<i80>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/webkit/PacProcessor;
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at java.lang.Class java.lang.Class.classForName(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:-2)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at java.lang.Class java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (Class.java:453)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at java.lang.Class android.webkit.WebViewFactory.getWebViewProviderClass(java.lang.ClassLoader) (WebViewFactory.java:176)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at java.lang.Class android.webkit.WebViewFactory.getProviderClass() (WebViewFactory.java:459)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at android.webkit.WebViewFactoryProvider android.webkit.WebViewFactory.getProvider() (WebViewFactory.java:251)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at android.webkit.WebViewFactoryProvider android.webkit.WebView.getFactory() (WebView.java:2681)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at void android.webkit.WebView.ensureProviderCreated() (WebView.java:2676)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at void android.webkit.WebView.setOverScrollMode(int) (WebView.java:2741)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at void android.view.View.<init>(android.content.Context) (View.java:4814)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at void android.view.View.<init>(android.content.Context, android.util.AttributeSet, int, int) (View.java:4955)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at void android.view.ViewGroup.<init>(android.content.Context, android.util.AttributeSet, int, int) (ViewGroup.java:659)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at void android.widget.AbsoluteLayout.<init>(android.content.Context, android.util.AttributeSet, int, int) (AbsoluteLayout.java:55)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at void android.webkit.WebView.<init>(android.content.Context, android.util.AttributeSet, int, int, java.util.Map, boolean) (WebView.java:659)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at void android.webkit.WebView.<init>(android.content.Context, android.util.AttributeSet, int, int) (WebView.java:604)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at void android.webkit.WebView.<init>(android.content.Context, android.util.AttributeSet, int) (WebView.java:587)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at void com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.WebViewYouTubePlayer.<init>(android.content.Context, android.util.AttributeSet, int) (WebViewYouTubePlayer.kt:27)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at void com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.WebViewYouTubePlayer.<init>(android.content.Context, android.util.AttributeSet, int, int, kotlin.jvm.internal.DefaultConstructorMarker) (WebViewYouTubePlayer.kt:26)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at void com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.LegacyYouTubePlayerView.<init>(android.content.Context, android.util.AttributeSet, int) (LegacyYouTubePlayerView.kt:32)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at void com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.LegacyYouTubePlayerView.<init>(android.content.Context) (LegacyYouTubePlayerView.kt:29)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at void com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView.<init>(android.content.Context, android.util.AttributeSet, int) (YouTubePlayerView.kt:28)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at void com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView.<init>(android.content.Context) (YouTubePlayerView.kt:25)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView com.flauschcode.omcast.MainActivityKt$MyYouTubePlayerView$2.invoke(android.content.Context) (MainActivity.kt:140)
2022-07-15 10:38:25.401 11975-11975/com.flauschcode.omcast I/uschcode.omcas:     at java.lang.Object com.flauschcode.omcast.MainActivityKt$MyYouTubePlayerView$2.invoke(java.lang.Object) (MainActivity.kt:134)
...

I'm only pasting the top of the stack trace since it is enormous, but the error can be easily reproduced with the sample app, too.

To be honest I don't really know anything about PacProcessor, but a quick search shows that this error seems indeed to be connected to different Chrome versions: https://stackoverflow.com/questions/70756680/java-lang-noclassdeffounderror-failed-resolution-of-landroid-webkit-pacprocess

@PierfrancescoSoffritti Do you have an idea about that?

@PierfrancescoSoffritti
Copy link
Owner

It could be related to the version of WebView.

The only idea I have is to try building a simple sample app with compose and try to fix it from there.

@flauschtrud
Copy link
Contributor

It's not a compose issue, both the black webview as the NoClassDefFoundError can be reproduced with the sample apps (with a new enough Chrome/Webview version). It's hard to tell whether they are independent problems or one causes the other, but they both seem to occur only with newer Chrome/Webview versions.

I'm willing to spend some time to look deeper into it, but do not have an idea yet where to start.

(but I updated all the dependencies in the core project and the sample app, this did not change anything)

@whogashaga
Copy link

If onReady() was not called, is there any way to reinitialize the PlayerView ?

PierfrancescoSoffritti added a commit that referenced this issue Aug 5, 2022
Defer loading the IFrame API to avoid race condition where the library loads before the page is parsed and tries to call `onYouTubeIframeAPIReady`.

Co-authored-by: Pierfrancesco Soffritti <[email protected]>
@PierfrancescoSoffritti
Copy link
Owner

Thanks to @flauschtrud , this will be available starting from version 11.1.0.

@sreejith-hme
Copy link

sreejith-hme commented Oct 21, 2022

UPDATE:
Found the cause. No issue with this library. It was because of third party payment gateway library holding Webview instance in memory and messing it up, which is causing youtube embed js not to load properly.


Similar issue is happening with latest version 11.1.0.

Player works fine initially, but stops working if any other webview is opened within the app.
In our app, there is webview browser to read webpages. Once that webview is opened, and then tries to load youtubeplayer in another activity, YoutubePlayerView is not loading webview and there is no onReady callback.

Tried reverting to 11.0.0. It is stuck with white youtubeplayer view.
In 11.1.0, white view comes, then goes black, but no web player.

Chrome debug shows there is content, but player not starting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests