Closed ghimiresiddhartha closed 5 months ago
Having same issue in recyclerview. also set null to playerView and youTubePlayer instance variable, still getting this error on re-initialization.
You can't re-initialize a released instance, you need to create a new one. So i don't think this is a bug.
But please let me know if you can replicate in the sample app.
Apologies for marking this as a bug. I wanted to ensure that re-initializing the instance was possible. I am closing this question with this comment.
Thank you for your assistance!
I did not want to provide lifecycle while playing the video instead I tried something like this step, removing the listener and releasing the player during onViewDetachFromWindow and reinitializing during onViewAttachToWindow. But I received the error This YouTubePlayerView has already been initialized. . While going through the source code, I found out that there is a variable check at LegacyYoutubePlayerView class named as isYouTubePlayerReady. And since it did not meet the requirement and it throw me this error.
I suggest you to try this code by yourself :
Scenario to recreate check the instance of the player. During onViewAttach, a new youtubePlayerView instance is created. And during on detach previously loaded instance is provided. Everytime a new playerView instance is created from onAttach, it releases the previously loaded playerViewInstance which is good but when I try to reinitialize the previously released playerView instance again, it provides me the error. I don't know what is wrong here, since I already cleared previously initialized view's listener and also released it during onViewDetachedFromWindow. Why am I not able to reinitialize during onViewAttachedToWindow?