NoClassDefFoundError Crash on Minimizing Youtube Player on Android 4.0, 4.2, 4.4

独自空忆成欢 提交于 2019-12-20 02:09:18

问题


Problem : Youtube Player crashes on minimizing youtube player activity/Fragment in the app.

Cause : Youtube Player Update

Code

public class YouTubePlayerActivity extends YouTubeBaseActivity
    implements YouTubePlayer.OnInitializedListener {

 private static final int RECOVERY_DIALOG_REQUEST = 1;   
private final String TAG = YouTubePlayerActivity.class.getSimpleName();   
private YouTubePlayerView youTubeView;   
private String videoId;  
 private YouTubePlayer youtubePlayer;

  @Override   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_youtube_player);
    videoId = getIntent().getExtras().getString(Constants.BUNDLE_VIDEO_ID);

    youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
    youTubeView.initialize(Constants.YOUTUBE_API_KEY, this);

  }

  @Override   public void onInitializationFailure(YouTubePlayer.Provider provider,
                                      YouTubeInitializationResult errorReason) {
    Log.d(TAG, "on Initialization failure : " + errorReason);   }

  @Override   public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
                                      boolean wasRestored) {
    youtubePlayer = player;
    youtubePlayer.setFullscreen(true);
    youtubePlayer.setShowFullscreenButton(false);
    youtubePlayer.setFullscreenControlFlags(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION
        | YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI);
    if (!wasRestored) {
      youtubePlayer.loadVideo(videoId);
    }   }

  @Override   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == RECOVERY_DIALOG_REQUEST) {
      youTubeView.initialize(Constants.YOUTUBE_API_KEY, this);
    }   }

  @Override   protected void onPause() {
    super.onPause();
    if(youtubePlayer != null) {
      youtubePlayer.pause();
    }   }

  @Override   protected void onDestroy() {
    super.onDestroy();
    if (youtubePlayer != null) {
      youtubePlayer.release();
    }   } }

来源:https://stackoverflow.com/questions/44571262/noclassdeffounderror-crash-on-minimizing-youtube-player-on-android-4-0-4-2-4-4

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