YouTube Android Player API throws “BadParcelableException ClassNotFoundException when unmarshalling: asc” with new YouTube version

前端 未结 4 1949
[愿得一人]
[愿得一人] 2020-12-31 18:50

Filing bug to YouTube Android Player API Library engineers: see android-youtube-api tag

Over the course of the past week and a half, I\'ve noticed t

4条回答
  •  耶瑟儿~
    2020-12-31 19:10

    Use following code in your onCreate:

    @Override
    public void onCreate(Bundle b) {
      if (b != null) {
        final ClassLoader contextCl = getClassLoader();
        b.setClassLoader(contextCl);
      }
      super.onCreate(b);
    }
    

    The bug is probably due to YouTube library code storing custom Parcelable inside the state Bundle (YouTube library classes are probably obfuscated by Proguard, hence weird names like "asc").

    If the suggestion above does not work, follow along the lines of @Fitz's suggestion and drop the state Bundle. Don't try to mess with it in onCreate (that won't work), instead it is best to override onSaveInstanceState to return Bundle.EMPTY if your app is suspended when you have a playback in progress.


    Note, that the bug in question is pretty tricky in multiple ways. If you (or YouTube app) store nested Bundles inside each other, those also need to have proper ClassLoader set… Someone should tell Google to get some common sense and just use Thread#getContextClassLoader inside Bundle to fix that problem once and for all.

提交回复
热议问题