Reputation: 200
I want to display some YouTube videos on my Android TV application, I was trying to port something I already have working on a phone, but there I use the YouTube Android API player, that doesn't seem to work on Android TV.
I found this https://code.google.com/p/gdata-issues/issues/detail?id=6998 so it looks like I'm not alone.
I added a WebView and I can display a video but I can't get full hd resolution, is that possible with embedded videos?
Upvotes: 3
Views: 2448
Reputation: 874
YouTube Player Full API is not available on Android TV but developers can currently use the YouTube intent as follows.
String videoId = "dQw4w9WgXcQ";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + videoId));
intent.putExtra("force_fullscreen", true);
intent.putExtra("finish_on_ended", true);
startActivity(intent);
This will use YouTube app to play videos. The force_fullscreen=true removes navigation to related videos while the finish_on_ended=true returns to calling app when video is done.
You may also use
Intent intent = YouTubeIntents.createPlayVideoIntentWithOptions(this, videoId, true, false);
if you download the YouTubeAndroidPlayerAPI:
https://developers.google.com/youtube/android/player/downloads/
and include the jar file in your project
Upvotes: 6
Reputation: 66
I tried loading into a webview and I get an error:
I/chromium﹕ [INFO:CONSOLE(12)] "The key "target-densitydpi" is not supported.", source: https://m.youtube.com/watch?vq=hd1080&v=VidV0n-3a_U (12)
If I use this it works:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
Upvotes: 0
Reputation: 8439
You would just need to have video URL telling to play in resolution you want:
String url = "https://www.youtube.com/v/VIDEOID?version=3&vq=hd1080";
WebView myWebView = (WebView) this.findViewById(R.id.webView1);
view.loadUrl(url);
Upvotes: 0