YouTubePlayerFragment backstack

ε祈祈猫儿з 提交于 2019-12-02 01:06:42

I've extend YouTubePlayerSupportFragment to store player instance and correctly release it in onDestroyView

public class YouTubePlayerFragment2 extends YouTubePlayerSupportFragment {
        private YouTubePlayer mPlayer;



        public static YouTubePlayerFragment2 newInstance(){
            return new YouTubePlayerFragment2();
        }

        @Override
        public void initialize(String s, YouTubePlayer.OnInitializedListener onInitializedListener) {
            YouTubePlayer.OnInitializedListener listener = new YouTubePlayer.OnInitializedListener() {
                @Override
                public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
                    onInitializedListener.onInitializationSuccess(provider, youTubePlayer, b);
                    mPlayer = youTubePlayer;
                    mPlayer.setShowFullscreenButton(false);
                }

                @Override
                public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
                    onInitializedListener.onInitializationFailure(provider, youTubeInitializationResult);
                }
            };
            super.initialize(s, listener);
        }

        @Override
        public void onDestroyView() {
            if(mPlayer!=null) {

                mPlayer.release();
            }
            super.onDestroyView();
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!