Android YouTube API "An error occurred while initializing YouTube player"



我有一个android应用程序,可以播放youtube视频。我正在使用最新的YouTube API(1.2.1)。我在android版本4.0.4,4.3,4.4.4或5.0,它工作得很好(在每个设备上都是YouTube应用程序版本10.-。但在一个设备上,android 4.0.4和YouTube应用程序4.4.11版本不工作,并出现错误"初始化YouTube播放器时出错"。在编写的文档中,YouTube应用程序的最低要求版本是4.2.16。所以我不知道,问题出在哪里。

有人有主意吗,出了什么问题,或者我该怎么解决?

非常感谢。。。

此问题出现在Android 11及以上版本中,原因是包可见性过滤

有限的应用程序可见性会影响提供其他应用程序信息的方法的返回结果,如queryIntentActivities()、getPackageInfo()和getInstalledApplications()。有限的可见性也会影响与其他应用程序的显式交互,例如启动另一个应用程序的服务。

有关更多信息:https://developer.android.com/training/package-visibility

将以下代码行添加到AndroidManifest.xml文件中

<queries>
   <intent>
      <action android:name="com.google.android.youtube.api.service.START" />
   </intent>
</queries>

将您的Android youtube应用程序更新到最新版本,它将适用于Sure!!

我从来没有想过要在那个位置查找设置。正如你所说的那样。

以下是关于设置知识较少的说明。

首先,您需要进入设置->电池-->应用程序发布>YouTube

现在禁用选项自动管理

禁用上述选项后,将显示一个弹出窗口。

现在启用选项辅助启动(可以由其他应用程序启动)

如果有人仍然收到此错误,则

问题出现在布局文件中,您是否定义了固定高度宽度

<com.google.android.youtube.player.YouTubePlayerView
    android:layout_width="123dp"
    android:layout_height="123dp" />

将高度和宽度替换为";wrap_content":

<com.google.android.youtube.player.YouTubePlayerView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

我将targetSdkVersion=30替换为targetSdkVersion=26,这对我来说很有效

apply plugin: 'com.android.application'
android {
    compileSdkVersion 30`enter code here`
    defaultConfig {
        applicationId "com.loopwiki.youtubeplayerexample"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:26.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation files('libs/YouTubeAndroidPlayerApi.jar')
}

最新更新