YouTubeThumbnailView没有抛出异常,但是视频无法正常运行

时间:2018-08-17 07:39:03

标签: android android-studio youtube-api android-youtube-api

我正在尝试在RecyclerViewAdapter中使用YouTubeThumbnailView作为以下代码 video_row_item

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.google.android.youtube.player.YouTubeThumbnailView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/youtube_player_view"
android:scaleType="centerCrop"/>
</android.support.constraint.ConstraintLayout>

在我的适配器(RecylerViewAdapter)中:

 @Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
                YotubeViewHolder youtubeViewHolder = (YotubeViewHolder) holder;
   youtubeViewHolder.youTubePlayerView.initialize(PlayerConfig.API_KEY, new YouTubeThumbnailView.OnInitializedListener() {
        @Override
        public void onInitializationSuccess(YouTubeThumbnailView youTubeThumbnailView, final YouTubeThumbnailLoader youTubeThumbnailLoader) {
            youTubeThumbnailLoader.setVideo("isqaRx5LuHI");
            youTubeThumbnailLoader.setOnThumbnailLoadedListener(new YouTubeThumbnailLoader.OnThumbnailLoadedListener() {
                @Override
                public void onThumbnailLoaded(YouTubeThumbnailView youTubeThumbnailView, String s) {
                    youtubeViewHolder.youTubePlayerView.setVisibility(View.VISIBLE);
                    youTubeThumbnailLoader.release();
                    Toast.makeText(context, "It's a valid youtube url.", Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onThumbnailError(YouTubeThumbnailView youTubeThumbnailView, YouTubeThumbnailLoader.ErrorReason errorReason) {
                    Toast.makeText(context, "youtube error happen", Toast.LENGTH_SHORT).show();
                }
            });
        }

        @Override
        public void onInitializationFailure(YouTubeThumbnailView youTubeThumbnailView, YouTubeInitializationResult youTubeInitializationResult) {
            Toast.makeText(context, "error happen", Toast.LENGTH_SHORT).show();
        }
    });

,但视频不起作用(即使不显示吐司消息(错误消息)), 当我调试它到达youTubeThumbnailLoader.setVideo("isqaRx5LuHI");时,下一步将在初始化失败后进入.. 我的意思是,成功,失败和错误根本无法执行 我的错误在哪里,如何解决?谢谢

0 个答案:

没有答案