【问题标题】:Android YouTube API "An error occurred while initializing YouTube player"Android YouTube API“初始化 YouTube 播放器时出错”
【发布时间】:2015-05-21 22:26:05
【问题描述】:

我有一个安卓应用,可以播放 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。所以我不知道,在哪里问题。

有人有什么想法,出了什么问题或我该如何解决?

非常感谢...

【问题讨论】:

  • 除了 4.0.4 之外的其他版本是否仍在工作?我得到了同样的错误,它不再在任何设备上工作。它最近在任何设备上都运行良好。
  • 在 YouTube 应用程序实现后,它已经开始正常工作了。然后手机被重置,YouTube 应用程序的版本再次为 4.2.16,但一切正常。很好奇。

标签: android youtube youtube-api android-youtube-api


【解决方案1】:

由于包可见性过滤

,此问题出现在 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 11 的设备,我面临同样的问题,但是在将这些代码行添加到 android 清单文件中后,它对我有用。
  • @Bilal 这应该是公认的答案
【解决方案2】:

将您的 Android youtube 应用更新到最新版本,它肯定会工作!!

【讨论】:

    【解决方案3】:

    我从没想过会在那个位置寻找设置。就像你说的那样有效。

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

    首先,您需要进入设置 -> 电池 -> 应用启动 -> YouTube。

    现在禁用选项自动管理。

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

    现在启用选项Secondary Launch(可以由其他应用启动)

    【讨论】:

      【解决方案4】:

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

      问题出在layout文件,可能是你定义了fixed height 宽度

      <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" />
      

      【讨论】:

        【解决方案5】:

        我将 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')
        }
        

        【讨论】:

        • 这只是一个糟糕的建议。
        猜你喜欢
        • 2013-03-05
        • 1970-01-01
        • 2023-04-04
        • 2013-05-23
        • 2019-01-11
        • 1970-01-01
        • 2014-11-12
        • 2016-08-12
        相关资源
        最近更新 更多