0

我想在一个新活动中启动一个 YouTubePlayer,我传递了意图中的选择,但播放器抛出了这个错误:

E/ActivityThread: Activity com.vjava.ar.VideoPlayer 泄露了ServiceConnection com.google.android.youtube.player.internal.r$e@94b7384 原来绑定在这里 android.app.ServiceConnectionLeaked: Activity com.vjava.ar。 VideoPlayer 泄露了原本绑定在这里的 ServiceConnection com.google.android.youtube.player.internal.r$e@94b7384

这是我的代码:


package com.vjava.ar;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;


public class VideoPlayer extends YouTubeBaseActivity {

    String videoFile = "XfRFbQ3CvYw";
    YouTubePlayerView youTubePlayerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_player);
        youTubePlayerView = (YouTubePlayerView) findViewById(R.id.player);
        Intent intent = getIntent();
        int opened = intent.getIntExtra("opened", 0);
        switch (opened) {
            case 0:
            case 1:
                videoFile = "SdnjROOeS4c";

        }
        playYouTube();
        Intent returnIntent = new Intent();
        setResult(Activity.RESULT_CANCELED, returnIntent);
        finish();
    }
    

    private void playYouTube() {
        youTubePlayerView.initialize("MY_DEV_KEY", new YouTubePlayer.OnInitializedListener() {
                    @Override
                    public void onInitializationSuccess(YouTubePlayer.Provider provider,
                                                        YouTubePlayer youTubePlayer, boolean b) {
                        youTubePlayer.cueVideo(videoFile);
                    }
                    @Override
                    public void onInitializationFailure(YouTubePlayer.Provider provider,
                                                        YouTubeInitializationResult youTubeInitializationResult) {

                    }
                });
    }
}

我在清单文件中设置允许的屏幕模式是横向:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.vjava.ar">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".VideoPlayer"
            android:screenOrientation="landscape">
        </activity>
        <activity
            android:name=".DailyContent"
            android:screenOrientation="landscape"
            ></activity>
        <activity android:name=".Content"
            android:screenOrientation="landscape">
        </activity>
        <activity
            android:name=".MainActivity"
            android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-permission android:name="android.permission.INTERNET" />

</manifest>

我在这里检查了所有相关问题,但其中一些是关于上下文的,其中一些是关于 YouTubePlayer 缩略图的。他们都没有帮助我。

4

0 回答 0