Android:错误初始化Youtube播放器

时间:2016-04-19 19:36:25

标签: android youtube youtube-api youtube-data-api android-youtube-api

我使用 YouTubeAndroidPlayerApi 在我的应用中实施了一个YouTube播放器来播放我添加到我的应用中的视频。当错误开始突然显现时,它工作得很好,直到两天。我一直试图解决这个问题,但都失败了。请帮帮我。

的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);



    }

onInitializationSuccess

  @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)  

任何人都可以指出这个问题是什么。提前谢谢。

1 个答案:

答案 0 :(得分:-1)

您的设备上是否有google youtube应用?

将youtube应用从Playstore更新到最新版本, 或者你可以安装它,如果你没有。 然后运行youtube app,

最后一步,再次尝试使用youtube播放器运行您自己的应用。 告诉我它是否有效。