Закрепляя видео Youtube в моем app Android

Я интегрирую видео Youtube в app Android. Прочитав несколько blogs, другие posts... я немного потерян ошибкой, которая у меня есть. layout, который я крашу:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
    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"
    android:orientation="horizontal"
    android:theme="@style/Theme.AppCompat.NoActionBar"
    tools:context=".UD1">

    <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/youtubePlayerView"
        android:layout_width="715dp"
        android:layout_height="461dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

</androidx.constraintlayout.widget.ConstraintLayout>

С другой стороны, Activity, которую я создал:

public class UD1 extends YouTubeBaseActivity {
    String APIkey = "aavvss";
    String video1 = "hjFaqDNUVFo";
    String video2 = "41cJ0mqWses";
    String video3 = "uT8-YdXPNBk";
    String video4 = "vSdAv931s-g";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ud1);
        final YouTubePlayerView youtubePlayerView = findViewById(R.id.youtubePlayerView);
        playVideo(video1, youtubePlayerView);

    }

    public void playVideo(final String videoId, YouTubePlayerView youTubePlayerView) {
        //initialize youtube player view
        youTubePlayerView.initialize(APIkey,new YouTubePlayer.OnInitializedListener() {
                @Override
                public void onInitializationSuccess(YouTubePlayer.Provider provider,
                                                    YouTubePlayer youTubePlayer, boolean b) {
                    youTubePlayer.cueVideo(videoId);
                }

                @Override
                public void onInitializationFailure(YouTubePlayer.Provider provider,
                                                    YouTubeInitializationResult youTubeInitializationResult) {

                }
            });
}

}

Однако, когда я скроллирую приложение, ошибка, которую я получаю, - следующая:

Caused by: java.lang. IllegalStateException: Хан only be created with an Activity which extends YouTubeBaseActivity схвати YouTubePlayerView its context.

Full stacktrace:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: es.elena.learninggame, PID: 8501
java.lang.RuntimeException: Unable to start activity ComponentInfo{es.elena.learninggame/es.elena.learninggame.UD1}: android.view.InflateException: Binary XML file line #11 in es.elena.learninggame:layout/ud1: Binary XML file line #11 in es.elena.learninggame:layout/ud1: Error inflating class com.google.android.youtube.player.YouTubePlayerView
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3260)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3396)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2009)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7319)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:934)
 Caused by: android.view.InflateException: Binary XML file line #11 in es.elena.learninggame:layout/ud1: Binary XML file line #11 in es.elena.learninggame:layout/ud1: Error inflating class com.google.android.youtube.player.YouTubePlayerView
 Caused by: android.view.InflateException: Binary XML file line #11 in es.elena.learninggame:layout/ud1: Error inflating class com.google.android.youtube.player.YouTubePlayerView
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance0(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
    at android.view.LayoutInflater.createView(LayoutInflater.java:854)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
    at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:438)
    at android.app.Activity.setContentView(Activity.java:3326)
    at es.elena.learninggame.UD1.onCreate(UD1.java:28)
    at android.app.Activity.performCreate(Activity.java:7783)
    at android.app.Activity.performCreate(Activity.java:7772)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3235)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3396)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2009)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7319)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:934)
 Caused by: java.lang.IllegalStateException: A YouTubePlayerView can only be created with an Activity  which extends YouTubeBaseActivity as its context.
    at com.google.android.youtube.player.YouTubePlayerView.<init>(Unknown Source:19)

E/AndroidRuntime: at com.google.android.youtube.player. YouTubePlayerView. (Unknown Source:1)... 28 обитал

Наблюдая app, мой Activity уже увеличивает YouTubeBaseActivity. Хотя, как я сказал раньше я прочитал несколько форумов, posts перед тем, как это печатать здесь, не смог встретить решения. Кто-то смог бы, пожалуйста бы, бы давать мне какой-то тип гида, на котором я врежу?

Большое спасибо заранее

5
задан 01.07.2019, 11:05
0 ответов