1
我正在嘗試添加youtube播放器API,並且在縮略圖可見性發生單擊事件時進度條出現,並且視頻開始播放時進度條消失。最初ProgressBar消失了。ProgressBar對於CardView中的所有位置都不可見
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);
}
});
}
但正在發生的事情,當我點擊任何的視頻第一次出現進度條和工作正常,但對於下一個視頻當我點擊進度條不會出現。我不明白爲什麼? 我希望進度條在卡片視圖中的所有位置都可見,當我點擊視頻縮略圖時。 任何人都可以幫助我嗎? 任何幫助將不勝感激 謝謝你!