对于CardView中的所有位置,ProgressBar不可见

时间:2017-07-16 18:12:02

标签: android android-cardview android-progressbar

我正在尝试添加youtube播放器API,并且当点击事件发生时,缩略图可见性消失并出现进度条,当视频开始播放时,进度条消失了。最初ProgressBar消失了。

layout.xml

<RelativeLayout
            android:id="@+id/rl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/hr"
            android:layout_centerHorizontal="true"
            android:gravity="center_horizontal">


            <com.example.prateek.videoplayertest.YoutubePlayerView        
                android:id="@+id/ytplayer"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="-3dp"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop">

                <ImageView
                    android:id="@+id/yt_thumbnail"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="-3dp"
                    android:adjustViewBounds="true"
                    android:background="#000000"
                    android:scaleType="fitXY">
                </ImageView>
            </com.example.prateek.videoplayertest.YoutubePlayerView>

            <ProgressBar
                android:id="@+id/item_progress"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:foregroundGravity="center"
                android:indeterminate="true"
                android:visibility="gone"
                android:layout_centerInParent="true" />


        </RelativeLayout>

RecyclerAdapter.java

@Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {

Picasso.with(context).load(video_thumbnail.get(position)).memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).into(holder.yt_video_thumb);
                holder.ytplayer.setVisibility(View.VISIBLE);
                holder.ytplayer.setAutoPlayerHeight(context);

                final YTParams params = new YTParams();
                params.setPlaybackQuality(PlaybackQuality.small);
                holder.yt_video_thumb.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        holder.flag_y = 1;
                        if(holder.flag_x == 1 && holder.flag_y == 1){
                            holder.ytplayer.play();
                        }
                            holder.yt_video_thumb.setVisibility(View.GONE);
                            holder.yt_progress.setVisibility(View.VISIBLE);
                    }
                });
                holder.ytplayer.initialize(video_id.get(position), params, new YoutubePlayerView.YouTubeListener() {

                    @Override
                    public void onReady() {
                        holder.flag_x = 1;
                        if(holder.flag_x == 1 && holder.flag_y == 1){
                            holder.ytplayer.play();
                        }

                        JLog.i("onReady()");
                    }

                    @Override
                    public void onStateChange(YoutubePlayerView.STATE state) {
                        /**
                         * YoutubePlayerView.STATE
                         *
                         * UNSTARTED, ENDED, PLAYING, PAUSED, BUFFERING, CUED, NONE
                         *
                         */
                        if(state == YoutubePlayerView.STATE.ENDED){
                            holder.yt_video_thumb.setVisibility(View.VISIBLE);                       }
                        if(state == YoutubePlayerView.STATE.BUFFERING){
                            if(holder.flag_x == 1 && holder.flag_y == 1){
                                holder.ytplayer.play();
                            }
                            holder.ytplayer.play();

                        }

                        if(state == YoutubePlayerView.STATE.PLAYING){
                            holder.yt_progress.setVisibility(View.GONE);
                            holder.flag_y = 0;
                            holder.flag_x = 0;
                            Log.d("ValueCHECK", holder.flag_y+" "+ holder.flag_x);
                        }
                        if(state == YoutubePlayerView.STATE.PAUSED){
                            holder.yt_video_thumb.setVisibility(View.VISIBLE);

                        }

                        JLog.i("onStateChange(" + state + ")");
                    }

                    @Override
                    public void onPlaybackQualityChange(String arg) {
                        JLog.i("onPlaybackQualityChange(" + arg + ")");
                    }

                    @Override
                    public void onPlaybackRateChange(String arg) {
                        JLog.i("onPlaybackRateChange(" + arg + ")");
                    }

                    @Override
                    public void onError(String arg) {
                        holder.yt_video_thumb.setVisibility(View.VISIBLE);
                        JLog.e("onError(" + arg + ")");
                    }

                    @Override
                    public void onApiChange(String arg) {
                        JLog.i("onApiChange(" + arg + ")");
                    }

                    @Override
                    public void onCurrentSecond(double second) {

                    }


                    @Override
                    public void onDuration(double duration) {
                        // total duration
                        JLog.i("onDuration(" + duration + ")");
                    }

                    @Override
                    public void logs(String log) {
                        // javascript debug log. you don't need to use it.
                        JLog.d(log);
                    }
                });
}

但是,当我第一次点击任何视频时,进度条出现并且工作正常但是当我点击进度条时下一个视频将不会出现。我不明白为什么? 当我点击视频缩略图时,我希望卡片视图中的所有位置都可以看到进度条。 谁能帮我? 任何帮助将不胜感激 谢谢!!!

1 个答案:

答案 0 :(得分:1)

最后,获得解决方案而不是设置progressBar GONE的可见性,设置Visibility INVISIBLE并初始设置progressBar INVISIBLE的可见性。 希望它会有所帮助。 谢谢