Nexus Player (Android TV) YouTubeAndroidPlayerApi error: "There was an error initializing the YouTube player."
I am using android player API to play some YouTube videos. My code is working fine:
Samsung S3
Samsung Galaxy Tab III
Nexus 7 (with Android 5.1.1)
But it doesn't work on Nexus Player. I am getting the error:
"An error occurred while initializing the YouTube player."
My Youtube app on Nexus player - version 1.0.5.5
I have not seen any indication that the youtube app is out of date or updated in any way. If this is a problem, I will give 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>
Thank you in advance
source to share
Thanks to suggestions and comments from dextor and ianhanniballake, I was able to get it to work well 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);
}
source to share
This is because the YouTube SDK for Android doesn't support Android TV yet.
Technically speaking, I believe the YouTube TV app has a different package name, and the YouTube SDK depends on the YouTube video display app installed (it acts like a "remote view" for YouTube). Although the SDK was recently updated to 1.2.1, no TV support was provided.
source to share