3

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

三星S3

三星 Galaxy Tab III

Nexus 7(安卓 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>

提前致谢

4

2 回答 2

3

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

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

于 2015-06-24T16:54:07.713 回答
1

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

    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-06-24T17:38:12.773 回答