我在我的应用程序中实现了一个YouTube播放器,使用YouTubeAndroidPlayerApi播放我添加到应用程序中的视频。一切都很顺利,直到两天前突然出现了一个错误。我一直试图解决这个问题,但都失败了。请帮帮我。
onCreate
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.youtube_lightbox);
final RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout_youtube_activity);
relativeLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
final YouTubePlayerView playerView = (YouTubePlayerView) findViewById(R.id.youTubePlayerView);
if (savedInstanceState != null) {
millis = savedInstanceState.getInt(KEY_VIDEO_TIME);
}
final Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey(KEY_VIDEO_ID)) {
mVideoId = extras.getString(KEY_VIDEO_ID);
} else {
finish();
}
playerView.initialize(API_KEY, this);
}
初始化成功
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
mPlayer = youTubePlayer;
youTubePlayer.setFullscreenControlFlags(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION);
youTubePlayer.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_SYSTEM_UI);
youTubePlayer.setOnFullscreenListener(new YouTubePlayer.OnFullscreenListener() {
@Override
public void onFullscreen(boolean b) {
isFullscreen = b;
}
});
if (mVideoId != null && !b) {
youTubePlayer.loadVideo(mVideoId);
}
if (b) {
youTubePlayer.seekToMillis(millis);
}
}
错误
E/YouTubeAndroidPlayerAPI: Error creating YouTubePlayerView
com.google.android.youtube.player.internal.w$a: Exception thrown by invoked constructor in com.google.android.youtube.api.jar.client.RemoteEmbeddedPlayer
at com.google.android.youtube.player.internal.w.a(Unknown Source)
at com.google.android.youtube.player.internal.w.a(Unknown Source)
at com.google.android.youtube.player.internal.w.a(Unknown Source)
at com.google.android.youtube.player.internal.ac.a(Unknown Source)
at com.google.android.youtube.player.YouTubePlayerView.a(Unknown Source)
at com.google.android.youtube.player.YouTubePlayerView$1.a(Unknown Source)
at com.google.android.youtube.player.internal.r.g(Unknown Source)
at com.google.android.youtube.player.internal.r$c.a(Unknown Source)
at com.google.android.youtube.player.internal.r$b.a(Unknown Source)
at com.google.android.youtube.player.internal.r$a.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at com.google.android.youtube.player.internal.w.a(Unknown Source)
at com.google.android.youtube.player.internal.w.a(Unknown Source)
at com.google.android.youtube.player.internal.w.a(Unknown Source)
at com.google.android.youtube.player.internal.ac.a(Unknown Source)
at com.google.android.youtube.player.YouTubePlayerView.a(Unknown Source)
at com.google.android.youtube.player.YouTubePlayerView$1.a(Unknown Source)
at com.google.android.youtube.player.internal.r.g(Unknown Source)
at com.google.android.youtube.player.internal.r$c.a(Unknown Source)
at com.google.android.youtube.player.internal.r$b.a(Unknown Source)
at com.google.android.youtube.player.internal.r$a.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.IllegalArgumentException: The concrete class implementing IObjectWrapper must have exactly *one* declared private field for the wrapped object. Preferably, this is an instance of the ObjectWrapper<T> class.
at tff.a(SourceFile:76)
at com.google.android.youtube.api.jar.client.RemoteEmbeddedPlayer.<init>(SourceFile:147)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at com.google.android.youtube.player.internal.w.a(Unknown Source)
at com.google.android.youtube.player.internal.w.a(Unknown Source)
at com.google.android.youtube.player.internal.w.a(Unknown Source)
at com.google.android.youtube.player.internal.ac.a(Unknown Source)
at com.google.android.youtube.player.YouTubePlayerView.a(Unknown Source)
at com.google.android.youtube.player.YouTubePlayerView$1.a(Unknown Source)
at com.google.android.youtube.player.internal.r.g(Unknown Source)
at com.google.android.youtube.player.internal.r$c.a(Unknown Source)
at com.google.android.youtube.player.internal.r$b.a(Unknown Source)
at com.google.android.youtube.player.internal.r$a.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
有人能指出问题出在哪里吗。提前谢谢。
你的设备上有谷歌youtube应用程序吗?
将youtube应用程序从playstore更新到最新版本,或者你可以安装它,如果你没有。然后运行youtube应用程序
最后一步,再次尝试使用youtube播放器运行您自己的应用程序。告诉我它是否有效。