I want to keep the player alive when the app is in background. I'm getting unregisterAudioFocusListener... from logs and the player stops. Are there any ways to keep it alive in background? I tried with a Service but it didn't work.
Thanks
Hi, yes, just don't pause the player when the Fragment/Activity pauses. That means: do not call the pause() method on YouTubePlayer and/or don't register YouTubePlayerView as a lifecycle observer.
Remember that you won't be able to publish on the PlayStore an app with that behavior.
You can read more here.
Let me know if this helps.
Great, thanks for your response. I think it's done now and I can close it
You're welcome!
Hello,
I tried with this but the player still stops when app is in the background. I also called play() method in onPause and onStop in Activity, but it is still not working.
Don't register YouTubePlayerView as lifecycle observable.
Thank you for your quick reply. I have commented the line where
YouTubePlayerView is registered as observable and it still doesn't work. Do
you have any idea why?
V V čet., 12. jul. 2018 ob 20:19 je oseba Pierfrancesco Soffritti <
[email protected]> napisala:
Don't register YouTubePlayerView as lifecycle observable.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/PierfrancescoSoffritti/android-youtube-player/issues/128#issuecomment-404604312,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJjFdKK92qeRPq-eTTXg7PSN_8ao67Olks5uF5NFgaJpZM4TxWs1
.
If you're not calling pause() and are not observing lifceycles it should work. Unfortunately I can't say much about your code. Try to debug it and let me know.
Well actually I have just copy pasted the code from github and commented
the line where YouTubePlayerView is registered as observable, so I haven't
made any changes.
I'm going to do a test with the sample app tomorrow morning. I'll let you know.
@divjad--- You're right, it doesn't seem to work anymore. Not sure why. Maybe they changed something in WebView?
Yes, it may be possible.
V V pet., 13. jul. 2018 ob 07:56 je oseba Pierfrancesco Soffritti <
[email protected]> napisala:
@divjad--- https://github.com/divjad--- You're right, it doesn't seem
to work anymore. Not sure why. Maybe they changed something in WebView?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/PierfrancescoSoffritti/android-youtube-player/issues/128#issuecomment-404733799,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJjFdH2XiJqQTlkkOuGLMZTi_4gmDfROks5uGDaUgaJpZM4TxWs1
.
Let me know if you discover something new.
Will do, and you please write me an email if you manage to solve the issue.
On Fri, 13 Jul 2018, 14:56 Pierfrancesco Soffritti, <
[email protected]> wrote:
Let me know if you discover something new.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/PierfrancescoSoffritti/android-youtube-player/issues/128#issuecomment-404825612,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AJjFdJO44uxkiTnqYwsviS_hf9pcfpMyks5uGJkWgaJpZM4TxWs1
.
Has anyone made any progress on the issue?
Hey, unfortunately I haven't had time to look into it yet
It looks very weird, as if when the activity is paused the WebView completely removed itself. When the activity is resumed the video doesn't even pick up where it left off but goes back to start.
I tried logging to see which methods get called when I pause or stop the activity. No matter what I do I only see the log statements from initWebView, play, pause, initalize and loadVideo while the log statement from destroy never appears, even if I kill the app.
Also tried overriding WebViewYouTubePlayer's onPause to log and see if it gets called when I pause the activity but apparently no, its log statement never appears either.
This issue will be fixed in the next release. It will be possible to enable background playback by calling YouTubePlayerView.enableBackgroundPlayback(true). For more info please refer to the doc.