我的应用使用Youtube Android SDK提供youtube视图。 没有问题显示视频,但在打开YouTube应用程序时崩溃与DeadObjectException。
我的代码如下所示
//init
FragmentTransaction fragmentTransaction = fm.beginTransaction();
YouTubePlayerSupportFragment fragment = new YouTubePlayerSupportFragment();
fragmentTransaction.replace(R.id.fragmentz, fragment);
fragmentTransaction.commit();
fragment.initialize(Constants.YOUTUBE_DEV_KEY, this);
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, final YouTubePlayer youTubePlayer, boolean wasRestored) {
if (!wasRestored) {
this.youTubePlayer = youTubePlayer;
this.youTubePlayer.setShowFullscreenButton(true);
try {
this.youTubePlayer.loadVideo(youtubeLink);
//other stuff
} catch (IllegalStateException e) {
Logger.e(e);
}
}
}
当1)直接通过意图移动到youtube应用程序或2)通过播放器视图上的youtube图标移动到youtube应用程序时崩溃。
崩溃日志如下所示
java.lang.IllegalStateException: android.os.DeadObjectException
at com.google.android.youtube.api.jar.client.RemoteEmbeddedPlayer.u(SourceFile:506)
at com.google.android.apps.youtube.api.jar.a.a.t(SourceFile:467)
at com.google.android.youtube.player.internal.h.onTransact(SourceFile:392)
at android.os.Binder.transact(Binder.java:361)
at com.google.android.youtube.player.internal.d$a$a.r(Unknown Source)
at com.google.android.youtube.player.internal.s.h(Unknown Source)
at com.google.android.youtube.player.YouTubePlayerView.e(Unknown Source)
at com.google.android.youtube.player.YouTubePlayerSupportFragment.onSaveInstanceState(Unknown Source)
at android.support.v4.app.Fragment.performSaveInstanceState(Fragment.java:1647)
at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1610)
at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1678)
at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:546)
at com.actionbarsherlock.app.SherlockFragmentActivity.onSaveInstanceState(SherlockFragmentActivity.java:127)
Caused by: android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at com.google.android.apps.youtube.api.b.a.aq.k(SourceFile:685)
at com.google.android.youtube.api.jar.client.RemoteEmbeddedPlayer.u(SourceFile:503)
at com.google.android.apps.youtube.api.jar.a.a.t(SourceFile:467)
at com.google.android.youtube.player.internal.h.onTransact(SourceFile:392)
at android.os.Binder.transact(Binder.java:361)
at com.google.android.youtube.player.internal.d$a$a.r(Unknown Source)
at com.google.android.youtube.player.internal.s.h(Unknown Source)
at com.google.android.youtube.player.YouTubePlayerView.e(Unknown Source)
at com.google.android.youtube.player.YouTubePlayerSupportFragment.onSaveInstanceState(Unknown Source)
at android.support.v4.app.Fragment.performSaveInstanceState(Fragment.java:1647)
请帮我解决这个问题。
我测试过nexus 5,android 4.4,youtube api 1.0,youtube app 5.3.24
答案 0 :(得分:1)
在youTubeView.initialize之后和onInitializationSuccess调用之前,当设备正在旋转(或其他导致活动重启的系统配置更改)时会发生这种情况。我的理解是,当您在此时旋转设备时,原始播放器对象将变为死亡,并且假设调用onInitializationSuccess的线程仍在运行,并且一旦该线程调用onInitializationSuccess,它将使用死播放器对象。
使用以下try catch包装您的播放器将解决问题:
try{
youtubeplayer.load(0..;
}catch (IllegalStateException ise){
//do nothing probably device go rotated
return;
}
* *答案提取自 https://code.google.com/p/gdata-issues/issues/detail?id=4395