Android YouTubePlayer API - YouTubeService leaked IntentReceiver - Failed to get ad id

I am using YouTube Player in Fragment in YouTubePlayerActivity

I am getting errors like this when using:

  • When opening the YouTube player:
    • Failed to get ad id java.lang.NullPointerException: try to read from field 'java.lang.String iwq.a' by null object reference

Is the ad required?

  • When you close the YouTube player activity:
    • The service com.google.android.youtube.api.service.YouTubeService leaked IntentReceiver udp @ bf4a7a, which was originally registered here. Are you missing the call to unregisterReceiver ()?

How can I prevent this error?

(Errors do not crash the application)

But the app pauses when I quickly open and close the YouTube hangout. java.lang.IllegalStateException: YouTubeServiceEntity is not initialized

public class YouTubePlayerFragment extends Fragment {

    private YouTubePlayerSupportFragment mYouTubePlayerFragment;
    private YouTubePlayer mYouTubePlayer;

    ...

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_youtube_player, container, false);

        mYouTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
        mYouTubePlayerFragment.initialize(VideoService.API_KEY, new YouTubePlayer.OnInitializedListener() {
            @Override
            public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) {
                if (!wasRestored) {
                    mYouTubePlayer = player;
                    mYouTubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
                    mYouTubePlayer.loadVideo(mVideoID);
                }
            }

            @Override
            public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult errorReason) {
                if (errorReason.isUserRecoverableError()) {
                    errorReason.getErrorDialog(getActivity(), RECOVERY_REQUEST).show();
                } else {
                    String error = String.format(getString(R.string.player_error), errorReason.toString());
                    Toast.makeText(getActivity(), error, Toast.LENGTH_LONG).show();
                }
            }
        });
        FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
        transaction.add(R.id.youtube_fragment, mYouTubePlayerFragment).commit();

        return view;
    }

    ...

}

      

Thanks for any help!

+3


source to share





All Articles