代码之家  ›  专栏  ›  技术社区  ›  P. Jaiswal

ProgressBar在CardView中的所有位置都不可见

  •  3
  • P. Jaiswal  · 技术社区  · 7 年前

    我试图添加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 回复  |  直到 7 年前
        1
  •  1
  •   P. Jaiswal    7 年前

    最后,得到了解决方案,只是不用设置progressBar的可见性,而是将可见性设置为不可见,并最初将progressBar的可见性设置为不可见。 非常感谢。