Bug Report
Leaking issue in LegacyYouTubePlayerView
Description of the Bug
In init block of LegacyYouTubePlayerView. You're adding the listener to NetworkBroadcastReceiver
networkObserver.listeners.add(object : NetworkObserver.Listener {
override fun onNetworkAvailable() {
if (!isYouTubePlayerReady) {
initialize()
}
else {
playbackResumer.resume(webViewYouTubePlayer.youtubePlayer)
}
}
override fun onNetworkUnavailable() { }
})
It will fine if the view is bound with a lifecycle like fragment/activity.
But in case the LegacyYouTubePlayerView is put on custom view which has no default lifecycle --> The listener will be leaked.
Recommendation
Moving the block adding the network state listener from init to view.doOnAttach { //Add network listener }
And remove it when view is going on detached by view.onViewDetached { //Remove network listener }
This will make all the user consistence and no need to care about the lifecycle of view.
Youtube Player Library Version: 10.0.5 or 0.23 (for chromecast)
Bug Report
Leaking issue in LegacyYouTubePlayerView
Description of the Bug
In init block of LegacyYouTubePlayerView. You're adding the listener to NetworkBroadcastReceiver
It will fine if the view is bound with a lifecycle like fragment/activity.
But in case the LegacyYouTubePlayerView is put on custom view which has no default lifecycle --> The listener will be leaked.
Recommendation
Moving the block adding the network state listener from init to
view.doOnAttach { //Add network listener }And remove it when view is going on detached by
view.onViewDetached { //Remove network listener }This will make all the user consistence and no need to care about the lifecycle of view.
Youtube Player Library Version: 10.0.5 or 0.23 (for chromecast)