I'm using the YouTube android player API to play some youtube videos. My code is working fine on:

Samsung S3

Samsung Galaxy Tab III

Nexus 7 (with Android 5.1.1)

But it doesn't work on the Nexus Player. I get the error:

"An error occurred when initializing the YouTube player."

My Youtube app on the Nexus player is version 1.0.5.5

I couldn't see any indications that the youtube app is out of date nor any way to update it. If that is the problem I will instructions on how to update it.

I think my manifest is ok:

<?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>

Thanks in advance

2

There are 2 answers

0
Ohiovr On BEST ANSWER

Thanks to the suggestions and comments from dextor and ianhanniballake I was able to get it to work good with the following code:

    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);
    }
1
Sebastiano On

This is because the YouTube SDK for Android does not (yet) support Android TV.

Technically speaking, I believe the YouTube for TV app has a different package name, and the YouTube SDK relies on the YouTube app to be installed in order to display videos (it acts as a "remote view" for YouTube). Even though the SDK was recently updated to 1.2.1, no TV support was introduced.