YouTube Android播放器API在亚马逊Fire TV上不起作用

rryofs0p  于 2023-03-16  发布在  Android
关注(0)|答案(1)|浏览(117)

我需要实现在亚马逊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;
    }
}

活动_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>

当我运行对话框时,点击按钮“获取YOUTUBE按钮”没有得到任何结果。回调onInitializationFailure中的值YouTubeInitializationResult errorReasonSERVICE_MISSING。Youtube应用程序安装在Amazon Fire TV中。
有人知道如何在亚马逊Fire TV中运行Youtube视频吗?

n8ghc7c1

n8ghc7c11#

我也遇到过同样的问题。
经过一番研究,我找到了可能的答案here
Levon@Amazon写道,Youtube视频播放器API是谷歌API的一部分,而不是Android API,所以这就是为什么不工作。
可能的解决办法是:

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

希望这能帮上忙

相关问题