gpt4 book ai didi

android - YouTube API for Android的java.lang.ClassCastException

转载 作者:行者123 更新时间:2023-12-03 05:25:18 27 4
gpt4 key购买 nike

尝试使用YouTube API播放视频时,出现以下错误。视频将初始化并显示缩略图,但是当您单击播放时,应用程序崩溃。

这仅在Android LG P925设备上发生。该视频实际上将在其他设备上播放。

这是错误:

03-04 20:20:49.140  10473-10496/? E/AndroidRuntime﹕ FATAL EXCEPTION: YouTubePlayer.MediaPlayerThread
java.lang.ClassCastException: com.google.android.apps.youtube.api.b.a.cx cannot be cast to android.view.S3DSurfaceHolder
at android.media.MediaPlayer.notifyS3DChanged(MediaPlayer.java:2102)
at android.media.MediaPlayer.start(MediaPlayer.java:938)
at com.google.android.apps.youtube.core.player.as.e(SourceFile:163)
at com.google.android.apps.youtube.core.player.ax.b(SourceFile:38)
at com.google.android.apps.youtube.core.player.bd.handleMessage(SourceFile:689)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)
03-04 20:20:51.164 232-286/? E/WifiStateMachine﹕ newRssi value = -55
03-04 20:20:52.890 139-231/? E/CrayonGraph-Base﹕ [setState] OMX.VisualOn.FileSource, state=0x1, error=0x80001012
03-04 20:20:52.890 139-231/? E/CrayonGraph-Base﹕ [setState] OMX.VisualOn.FileSource, state=0x1, error=0x80001012
03-04 20:20:52.898 139-10509/? E/CrayonGraph-Base﹕ [setState] OMX.VisualOn.FileSource, state=0x1, error=0x80001012
03-04 20:20:52.992 10293-10293/com.nickprofitt.YoutubeListing E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: android.os.DeadObjectException
at com.google.android.apps.youtube.api.jar.a.eo.surfaceDestroyed(SourceFile:236)
at android.view.SurfaceView.updateWindow(SurfaceView.java:581)
at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:245)
at android.view.View.dispatchDetachedFromWindow(View.java:9905)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2266)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2266)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:3581)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:3561)
at android.view.ViewGroup.removeView(ViewGroup.java:3509)
at com.google.android.youtube.player.YouTubePlayerView$1.b(Unknown Source)
at com.google.android.youtube.player.internal.r.h(Unknown Source)
at com.google.android.youtube.player.internal.r$e.onServiceDisconnected(Unknown Source)
at android.app.LoadedApk$ServiceDispatcher.doDeath(LoadedApk.java:1076)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1090)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4516)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at com.google.android.apps.youtube.api.b.a.be.a(SourceFile:221)
at com.google.android.apps.youtube.api.jar.a.eo.surfaceDestroyed(SourceFile:233)
at android.view.SurfaceView.updateWindow(SurfaceView.java:581)
at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:245)
at android.view.View.dispatchDetachedFromWindow(View.java:9905)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2266)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2266)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:3581)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:3561)
at android.view.ViewGroup.removeView(ViewGroup.java:3509)
at com.google.android.youtube.player.YouTubePlayerView$1.b(Unknown Source)
at com.google.android.youtube.player.internal.r.h(Unknown Source)
at com.google.android.youtube.player.internal.r$e.onServiceDisconnected(Unknown Source)
at android.app.LoadedApk$ServiceDispatcher.doDeath(LoadedApk.java:1076)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1090)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4516)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)

这是代码:
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored)
{
ytPlayer = player;

player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION
| YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI
| YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE);

if(!wasRestored)
{
player.cueVideo(FeedAccount.getInstance().getVideoIDArray()[FeedAccount.getInstance().getSelectionIndex()]);
final YouTubePlayer mPlayer = player;
ytPlayer.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {
@Override
public void onFullscreen(boolean fullsize) {
if (fullsize) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else
{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
});

player.setPlaybackEventListener(new YouTubePlayer.PlaybackEventListener() {
@Override
public void onPlaying() {
if(!wasPlaying)
{
wasPlaying = true;
mPlayer.setFullscreen(true);
}
}

@Override
public void onPaused() {

}

@Override
public void onStopped() {
}

@Override
public void onBuffering(boolean b) {

}

@Override
public void onSeekTo(int i) {

}
});
}
}

最佳答案

使用loadVideo(video_id)代替cueVideo(video_id),这对我有帮助

关于android - YouTube API for Android的java.lang.ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22273054/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com