在一个PlayerView中加载多个YouTube视频

问题描述

我的计划是从json文件中读取两个youtubelink,并在一个youtubeplayerview中使用两个按钮加载它们。

这是我的代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity"
    android:orientation="horizontal"
    android:padding="16dp">

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


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

            
                <ImageButton
                    android:id="@+id/button"
                    android:layout_width="44dp"
                    android:layout_height="51dp"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/youtube" />

           
            </LinearLayout>

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


                <ImageButton
                    android:id="@+id/button2"
                    android:layout_width="44dp"
                    android:layout_height="51dp"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/youtube" />

                 </LinearLayout>

       

            <view
                android:id="@+id/youtube_view"
                class="com.google.android.youtube.player.YouTubePlayerView"
                android:layout_width="171dp"
                android:layout_height="120dp"
                android:layout_above="@+id/button" />


        </LinearLayout>
   

</RelativeLayout>

当我按下第一个或第二个按钮时,它会起作用,并且第一个或第二个youtube链接会加载到视图中。但是按下一个按钮后,便无法按下第二个按钮。看来,该应用程序已重新启动(youtubeview除外),并且该按钮没有任何功能

那是我的xml:

{{1}}

您有任何想法如何打开并保持前面的步骤吗? 谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)