Android和YoutubePlayer:创建YouTubePlayerView时出错

时间:2016-05-12 07:50:46

标签: android android-fragments youtube youtube-api android-youtube-api

我遇到了YoutubePlayer的问题,我把它放在这样的片段中:

public class VideoFragment extends YouTubePlayerSupportFragment {

public VideoFragment() { }

public static Fragment newInstance(String url) {

    VideoFragment f = new VideoFragment();

    Bundle b = new Bundle();
    b.putString("url", url);

    f.setArguments(b);
    f.init(Constants.YOUTUBE_DEV_KEY);

    return f;
}

private void init(String api) {

    initialize(api, new YouTubePlayer.OnInitializedListener() {

        @Override
        public void onInitializationFailure(YouTubePlayer.Provider arg0, YouTubeInitializationResult arg1) { }

        @Override
        public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) {
            if (!wasRestored) {
                player.cueVideo(getArguments().getString("url"));
            }
        }
    });
}

我用这种方式从我的其他片段中调用它:

Fragment f = VideoFragment.newInstance(User.getVideoId());
        getFragmentManager().beginTransaction().replace(R.id.fragment_container, f).commit();

但是,我一直收到这个错误:

  

YouTubeAndroidPlayerAPI:创建YouTubePlayerView时出错                                                                                                  com.google.android.youtube.player.internal.w $ a:抛出的异常   调用的构造函数   com.google.android.youtube.api.jar.client.RemoteEmbeddedPlayer                                                                                                      在com.google.android.youtube.player.internal.w.a(未知来源)                                                                                                      在com.google.android.youtube.player.internal.w.a(未知来源)                                                                                                      在com.google.android.youtube.player.internal.w.a(未知来源)                                                                                                      在com.google.android.youtube.player.internal.ac.a(未知来源)                                                                                                      在com.google.android.youtube.player.YouTubePlayerView.a(未知   资源)                                                                                                      在com.google.android.youtube.player.YouTubePlayerView $ 1.a(未知   资源)                                                                                                      在com.google.android.youtube.player.internal.r.g(未知来源)                                                                                                      在com.google.android.youtube.player.internal.r $ c.a(未知来源)                                                                                                      在com.google.android.youtube.player.internal.r $ b.a(未知来源)                                                                                                      在   com.google.android.youtube.player.internal.r $ a.handleMessage(未知   源)......

1 个答案:

答案 0 :(得分:0)

不完全是一个修复程序,但如果你的应用程序用户体验它,你可以使用YouTubeStandalonePlayer。我对YouTubePlayerActivity和独立播放器都有同样的问题。