0

我需要在 Amazon Fine TV 中实现播放 Youtube 视频。我决定使用https://developers.google.com/youtube/android/player/。我的活动是:

package com.ticketmaster.amazon.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
import com.ticketmaster.amazon.R;
import com.ticketmaster.api.helper.PropertiesHelper;

/**
 * Created by Georgii on 4/26/2016.
 */
public class PlaybackYoutubeActivity extends YouTubeBaseActivity implements  YouTubePlayer.OnInitializedListener {
    private static final int RECOVERY_REQUEST = 1;
    public static final String YOUTUBE_KEY = "-----MYKEY----------";
    private YouTubePlayerView youTubeView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_youtube);

        youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
        PropertiesHelper.loadProperties(this);
        youTubeView.initialize(YOUTUBE_KEY, this);
    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) {
        if (!wasRestored) {
            player.cueVideo("fhWaJi1Hsfo"); // Plays https://www.youtube.com/watch?v=fhWaJi1Hsfo
        }
    }

    @Override
    public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult errorReason) {
        if (errorReason.isUserRecoverableError()) {
            errorReason.getErrorDialog(this, RECOVERY_REQUEST).show();
        } else {
            String errMsg = getString(R.string.video_error_unknown_error);
            Toast.makeText(this, errMsg, Toast.LENGTH_LONG).show();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == RECOVERY_REQUEST) {
            // Retry initialization if user performed a recovery action
            getYouTubePlayerProvider().initialize(YOUTUBE_KEY, this);
        }
    }

    protected YouTubePlayer.Provider getYouTubePlayerProvider() {
        return youTubeView;
    }
}

activity_youtube.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout mlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".activity.PlaybackYoutubeActivity">

<com.google.android.youtube.player.YouTubePlayerView
  android:id="@+id/youtube_view"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"/>

</RelativeLayout>

当我运行对话框时,点击按钮“GET YOUTUBE BUTTON”没有得到任何结果。回调 onInitializationFailure 中YouTubeInitializationResult errorReason值为SERVICE_MISSING。Youtube 应用程序安装在 Amazon Fire TV 中。

有谁知道如何在 Amazon Fire TV 中运行 Youtube 视频?

4

1 回答 1

3

我遇到了同样的问题。

经过一些研究,我在这里找到了可能的答案

Levon@Amazon 写道,Youtube Video Player API 是 Google API 的一部分,而不是 Android API,所以这就是为什么不工作的原因。

可能的解决方案可能是:

  • 侧载 Google Play 服务
  • 在 WebView 中显示 YouTube 视频

希望这可以帮助

于 2016-11-29T16:15:58.407 回答