YouTube的SDK崩溃与DeadObjectException时移至YouTube应用 [英] Youtube SDK crashes with DeadObjectException when move to youtube app

查看:1626
本文介绍了YouTube的SDK崩溃与DeadObjectException时移至YouTube应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序提供了使用YouTube的Andr​​oid SDK YouTube的看法。 没问题,显示出影片,但它与DeadObjectException打开YouTube应用程序时崩溃。

My app provides youtube view using Youtube Android SDK. No problem showing videos but it crashes with DeadObjectException when opening youtube app.

我的code是象下面

//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);
        }
    }
}

和它通过YouTube图标播放器视图崩溃时1)搬迁到YouTube应用程序直接通过故意或2)移动到YouTube应用程序。

and it crashes when 1) move to youtube app directly via intent or 2) move to youtube app via youtube icon on player view.

崩溃日志中包含

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)

请帮我解决这个问题。

我的关系5测试,Android 4.4系统,YouTube的API 1.0,YouTube应用程序5.3.24

I've tested on nexus 5, android 4.4, youtube api 1.0, youtube app 5.3.24

推荐答案

这发生在设备旋转youTubeView.initialize后(导致活动重新启动或其他系统配置的变化)和onInitializationSuccess之前调用。我的理解是,当你旋转你的设备就在这个时候原来的选手对象将变成死的,并且假设调用onInitializationSuccess仍在运行,一旦该线程调用onInitializationSuccess它会用死人选手对象。螺纹

This happens when the device is rotating (Or other system config change that cause activity to restart) after youTubeView.initialize and before onInitializationSuccess are called. My understanding is when your rotate your device in this time the original player object will become dead and the thread that suppose to call onInitializationSuccess is still running and once that thread calls onInitializationSuccess it will use the dead player object.

包裹你的播放器具有以下尝试捕捉将解决这个问题:

wrap your player with the following try catch will solve the problem:

try{
   youtubeplayer.load(0..;
}catch (IllegalStateException ise){
   //do nothing probably device go rotated
   return;
}

* 的*答案提取 的https://$c$c.google.com / P / GDATA-问题/问题/详细信息?ID = 4395

这篇关于YouTube的SDK崩溃与DeadObjectException时移至YouTube应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆