Java 下一步和后退按钮YouTube播放列表android studio don';行不通

Java 下一步和后退按钮YouTube播放列表android studio don';行不通,java,android,xml,android-studio,youtube,Java,Android,Xml,Android Studio,Youtube,单击“下一步”按钮时,将加载视频编号1,但再次单击时,仅更新标题,而不更新视频id。我认为函数getLifecycle()。添加观察者(youTubePlayerView); 它只工作一次。每次按下其中一个按钮时,有什么解决方案使其更新 我想在用户按下下一步按钮和后退按钮时更新地址和id 界面将每次刷新 主Java代码 package com.pharaoh.csis; public class DataStructureCourse extends AppCompatActivity {

单击“下一步”按钮时,将加载视频编号1,但再次单击时,仅更新标题,而不更新视频id。我认为函数getLifecycle()。添加观察者(youTubePlayerView); 它只工作一次。每次按下其中一个按钮时,有什么解决方案使其更新

我想在用户按下下一步按钮和后退按钮时更新地址和id 界面将每次刷新

主Java代码

package com.pharaoh.csis;

public class DataStructureCourse extends AppCompatActivity {

YouTubePlayerView youTubePlayerView;
TextView videoTitle;
Button backBtn, nextBtn;
int videoNumber = 0;
String youtubeVideoId = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_data_structure_course);

    videoTitle = findViewById(R.id.videoTitle);
    backBtn = findViewById(R.id.backBtn);
    nextBtn = findViewById(R.id.nextBtn);

    youTubePlayerView = findViewById(R.id.youtube_player_view);

    backBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            videoNumber--;
            videoNum();
        }
    });
    nextBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            videoNumber++;
            videoNum();
        }
    });

}

public void videoNum(){
    switch (videoNumber) {
        case 0:
            videoTitle.setText("#00 [Data Structures] - Introduction");
            youtubeVideoId = "owCqVRbZlbg";
            getLifecycle().addObserver(youTubePlayerView);
            setVideoId();
            break;
        case 1:
            videoTitle.setText("#01 [Data Structures] - Complexity");
            youtubeVideoId = "sHhVsGQz9MI";
            getLifecycle().addObserver(youTubePlayerView);
            setVideoId();
            break;
        case 2:
            videoTitle.setText("#02 [Data Structures] - Introduction To Stack");
            youtubeVideoId = "vdPNQzgBu_I";
            getLifecycle().addObserver(youTubePlayerView);
            setVideoId();
            break;
        case 3:
            videoTitle.setText("#03 [Data Structures] - Stack Implementation");
            youtubeVideoId = "N4o69Gqarhc";
            getLifecycle().addObserver(youTubePlayerView);
            setVideoId();
            break;
        case 4:
            videoTitle.setText("#04 [Data Structures] - Stack Using Linked List(Linked Stack)-Part 
1");
            youtubeVideoId = "9BZlgbZFR_c";
            getLifecycle().addObserver(youTubePlayerView);
            setVideoId();
            break;
        case 5:
            videoTitle.setText("#05 [Data Structures] - Stack Using Linked List Implementation");
            youtubeVideoId = "XSm6MivqBrM";
            getLifecycle().addObserver(youTubePlayerView);
            setVideoId();
            break;
        case 6:
            videoTitle.setText("#06 [Data Structures] - Balanced Parentheses Using Stack {([ ])}");
            youtubeVideoId = "PLvD3pHaWHQ";
            getLifecycle().addObserver(youTubePlayerView);
            setVideoId();
            break;
        case 7:
            videoTitle.setText("#07 [Data Structures] - Expression Evaluation Using Stack");
            youtubeVideoId = "Q4X7pZ5pyA4";
            getLifecycle().addObserver(youTubePlayerView);
            setVideoId();
            break;
        case 8:
            videoTitle.setText("#08 [Data Structures] - Infix To Postfix Using Stack");
            youtubeVideoId = "xhcChs9jijM";
            getLifecycle().addObserver(youTubePlayerView);
            setVideoId();
            break;
        case 9:
            videoTitle.setText("#09 [Data Structures] - Queue Introduction(Simple Queue vs Circular 
Queue Using Array)");
            youtubeVideoId = "8t_tzT52br8";
            getLifecycle().addObserver(youTubePlayerView);
            setVideoId();
            break;
        
    }
}

public void setVideoId(){

    youTubePlayerView.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
        @Override
        public void onReady(@NonNull YouTubePlayer youTubePlayer) {
            String videoId = youtubeVideoId;
            youTubePlayer.loadVideo(videoId, 0);
        }
    });
}

}
用于显示播放列表的我的XML代码

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DataStructureCourse">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/videoTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:fontFamily="sans-serif-condensed-medium"
        android:text="#00 [Data Structures] - Introduction"
        android:textAlignment="center"
        android:textColor="@color/color1"
        android:textSize="18sp" />

    <com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
        android:id="@+id/youtube_player_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:autoPlay="false"
        app:showFullScreenButton="false"/>



    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_margin="16dp"
        android:layout_height="wrap_content">
        <Button
            android:id="@+id/backBtn"
            android:layout_width="65dp"
            android:layout_alignParentStart="true"
            android:background="@drawable/ic_arrow_back"
            android:layout_height="65dp"/>
        <TextView
            android:layout_below="@id/backBtn"
            android:layout_marginTop="-10dp"
            android:layout_width="65dp"
            android:layout_alignParentStart="true"
            android:textAlignment="center"
            android:layout_height="wrap_content"
            android:text="Back"/>

        <Button
            android:id="@+id/nextBtn"
            android:layout_width="65dp"
            android:layout_alignParentEnd="true"
            android:background="@drawable/ic_arrow_next"
            android:layout_height="65dp"/>
        <TextView
            android:layout_below="@id/backBtn"
            android:layout_marginTop="-10dp"
            android:layout_width="65dp"
            android:layout_alignParentEnd="true"
            android:textAlignment="center"
            android:layout_height="wrap_content"
            android:text="Next"/>
    </RelativeLayout>

</LinearLayout>
</ScrollView>