Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nexus Player(Android TV)YouTubeAndroidPlayerApi错误:“0”;初始化YouTube播放器时出错。”;_Android_Android Youtube Api_Android Tv - Fatal编程技术网

Nexus Player(Android TV)YouTubeAndroidPlayerApi错误:“0”;初始化YouTube播放器时出错。”;

Nexus Player(Android TV)YouTubeAndroidPlayerApi错误:“0”;初始化YouTube播放器时出错。”;,android,android-youtube-api,android-tv,Android,Android Youtube Api,Android Tv,我正在使用YouTube android播放器API播放一些YouTube视频。我的代码在以下方面运行良好: 三星S3 三星Galaxy Tab III Nexus7(搭载安卓5.1.1) 但它在Nexus播放器上不起作用。我得到一个错误: “初始化YouTube播放器时出错。” 我在Nexus播放器上的Youtube应用程序是1.0.5.5版 我看不到任何迹象表明youtube应用已经过时,也看不到任何更新的方法。如果这是问题,我将提供有关如何更新的说明 我想我的舱单没问题: <?xml

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

三星S3

三星Galaxy Tab III

Nexus7(搭载安卓5.1.1)

但它在Nexus播放器上不起作用。我得到一个错误:

“初始化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的YouTube SDK(尚未)支持Android电视


从技术上讲,我认为YouTube for TV应用程序具有不同的软件包名称,YouTube SDK依赖于要安装的YouTube应用程序来显示视频(它充当YouTube的“远程视图”)。尽管SDK最近更新为1.2.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);
    }

需要注意的一点是,许多API都可以在Android TV上运行,即使其他API都不能运行。