【问题标题】:Nexus Player (Android TV) YouTubeAndroidPlayerApi error: "An error occurred when initializing the YouTube player."Nexus Player (Android TV) YouTubeAndroidPlayerApi 错误:“初始化 YouTube 播放器时出错。”
【发布时间】:2023-04-04 13:55:02
【问题描述】:

我正在使用 YouTube android 播放器 API 播放一些 youtube 视频。我的代码运行良好:

三星 S3

三星 Galaxy Tab III

Nexus 7(搭载 Android 5.1.1)

但它不适用于 Nexus Player。我得到错误:

“初始化 YouTube 播放器时出错。”

我在 Nexus 播放器上的 Youtube 应用是 1.0.5.5 版

我看不到任何迹象表明 youtube 应用程序已过时,也没有任何更新方法。如果这是问题,我将说明如何更新它。

我认为我的清单没问题:

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

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".vodActivity" />
        <activity
            android:name=".youtubePlayer"
            android:label="@string/title_activity_youtube_player" >
        </activity>
        <activity
            android:name=".webviewInfo"
            android:label="@string/title_activity_webview_info" >
        </activity>
    </application>

</manifest>

提前致谢

【问题讨论】:

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


    【解决方案1】:

    这是因为适用于 Android 的 YouTube SDK(尚)不支持 Android TV。

    从技术上讲,我认为 YouTube for TV 应用具有不同的包名称,并且 YouTube SDK 依赖于安装的 YouTube 应用来显示视频(它充当“远程观看”用于 YouTube)。即使 SDK 最近更新到 1.2.1,也没有引入电视支持。

    【讨论】:

    • 需要注意的一点是,许多YouTubeIntents确实可以在 Android TV 上运行,即使其他 API 都不起作用。
    【解决方案2】:

    感谢 dextor 和 ianhanniballake 的建议和 cmets,我能够使用以下代码使其正常工作:

        String videoID = "ARM42-eorzE";//youtube video id
        if (getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEVISION)
                || getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)){
            Intent youtubeIntent = YouTubeIntents.createPlayVideoIntent(getContext(), videoID);
            context.startActivity(youtubeIntent);
        } else {
            Intent myIntent = new Intent(getContext(), youtubePlayer.class);
            myIntent.putExtra("youtubeID",videoID);
            context.startActivity(myIntent);
        }
    

    【讨论】:

      猜你喜欢
      • 2015-05-21
      • 2013-03-05
      • 1970-01-01
      • 2020-11-29
      • 2016-08-12
      • 1970-01-01
      • 2019-06-09
      • 1970-01-01
      相关资源
      最近更新 更多