我有一个Android应用程序,它使用youtube播放器播放来自youtube数据api的视频。最近我经常在崩溃报告中收到此错误。
这是崩溃报告堆栈跟踪:
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.abc/com.abc.videos.videoplayer.VideoPlayerActivity}: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: asc
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2423)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
Caused by android.os.BadParcelableException: ClassNotFoundException when unmarshalling: asc
at android.os.Parcel.readParcelableCreator(Parcel.java:2432)
at android.os.Parcel.readParcelable(Parcel.java:2358)
at android.os.Parcel.readValue(Parcel.java:2264)
at android.os.Parcel.readSparseArrayInternal(Parcel.java:2675)
at android.os.Parcel.readSparseArray(Parcel.java:1967)
at android.os.Parcel.readValue(Parcel.java:2321)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2614)
at android.os.BaseBundle.unparcel(BaseBundle.java:224)
at android.os.Bundle.getSparseParcelableArray(Bundle.java:856)
at com.android.internal.policy.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2032)
at android.app.Activity.onRestoreInstanceState(Activity.java:1015)
at android.app.Activity.performRestoreInstanceState(Activity.java:970)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1164)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
我的youtube播放器代码在这里:
public class VideoPlayerActivity extends YouTubeFailureRecoveryActivity implements
YouTubePlayer.OnFullscreenListener, View.OnClickListener,VideoPlayerContract.View {
private String TAG = "VideoPlayerActivity";
@BindView(R.id.youtube_player)
YouTubePlayerView mYouTubePlayerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
ButterKnife.bind(this);
doLayout();
}
@Override
public void onFullscreen(boolean isfullscreen) {
fullscreen = isfullscreen;
Log.d(TAG, String.valueOf(fullscreen));
if (!fullscreen){
mToolBar.setVisibility(View.VISIBLE);
mAppBarLayout.setExpanded(true);
setRequestedOrientation(PORTRAIT_ORIENTATION);
} else {
mToolBar.setVisibility(View.GONE);
mAppBarLayout.setExpanded(false);
}
doLayout();
}
protected void onNewIntent(Intent intent) {
mFeedInitiater = (FeedInitiater) intent.getSerializableExtra(Constants.FEEDINITIATER);
mVideoID = intent.getStringExtra(Constants.VIDEOID);
videoTitle = intent.getStringExtra(Constants.VIDEOTITLE);
videoDescription = intent.getStringExtra(Constants.VIDEODESCRIPTION);
videoPublishedDate = UtilsFunctions.getFeedsDate(intent
.getLongExtra(Constants.VIDEOPUBLISHEDDATE,0));
videoViews = intent.getStringExtra(Constants.VIDEOCOUNT);
playVideo();
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider,
YouTubePlayer youTubePlayer, boolean wasRestored) {
mYoutubePlayer = youTubePlayer;
mYoutubePlayer = youTubePlayer;
mYoutubePlayer.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
int controlFlags = mYoutubePlayer.getFullscreenControlFlags();
controlFlags |= YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE;
mYoutubePlayer.setFullscreenControlFlags(controlFlags);
mYoutubePlayer.setOnFullscreenListener(this);
if (!wasRestored && mVideoID != null && !mVideoID.equals("")) {
mYoutubePlayer.loadVideo(mVideoID);
}
}
@Override
protected YouTubePlayer.Provider getYouTubePlayerProvider() {
return mYouTubePlayerView;
}
private void doLayout() {
final LinearLayout.LayoutParams playerParams =
(LinearLayout.LayoutParams) mYouTubePlayerView.getLayoutParams();
if (fullscreen && getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE) {
new Handler().post(new Runnable() {
@Override
public void run() {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
final int flags =
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
getWindow().getDecorView().setSystemUiVisibility(flags);
final View decorView = getWindow().getDecorView();
decorView
.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
{
@Override
public void onSystemUiVisibilityChange(int visibility)
{
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
{
} else {
mFeedsContent.setVisibility(View.GONE);
playerParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
playerParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
}
}
});
}
});
} else {
new Handler().post(new Runnable() {
@Override
public void run() {
final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
getWindow().getDecorView().setSystemUiVisibility(flags);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
playerParams.width = LinearLayout.LayoutParams.MATCH_PARENT;
playerParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
mFeedsContent.setVisibility(View.VISIBLE);
}
});
}
}
@Override
protected void onResume() {
super.onResume();
if (mYoutubePlayer != null)
mYoutubePlayer.play();
}
@Override
protected void onPause() {
super.onPause();
if (mYoutubePlayer != null)
mYoutubePlayer.pause();
}
@Override
public void playVideo() {
mYouTubePlayerView.initialize(Constants.YOUTUBEDEVELOPERKEY,this);
}
@Override
public void setPresenter(VideoPlayerContract.Presenter presenter) {
mPresenter = presenter;
if (mFeedInitiater != FeedInitiater.FEEDS){
mPresenter.loadVideoDetails(mVideoID);
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
doLayout();
}
在清单文件中,我已声明:
<activity android:name=".videos.videoplayer.VideoPlayerActivity"
android:screenOrientation="sensor"android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
我的代码中是否有任何问题,或者这是youtube播放器的问题以及如何处理此问题?