Android Youtube Player Api - ERROR_CONNECTING_TO_SERVICE

Android Youtube Player Api - ERROR_CONNECTING_TO_SERVICE(Android Youtube Player Api - ERROR_CONNECTING_TO_SERVICE)
本文介绍了Android Youtube Player Api - ERROR_CONNECTING_TO_SERVICE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用新的 api youtube.我按照提供的示例进行操作,但出现错误:ERROR_CONNECTING_TO_SERVICE

I'm trying to use the new api youtube. I followed the examples provided, but I get the error: ERROR_CONNECTING_TO_SERVICE

我使用的API 密钥"是正确的(因为它在 google 演示中可以正常工作).

The "API key" that I'm using is correct (since it works correctly in the google demos).

进口:

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.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerView;

类定义:

public class Track extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {

     private YouTubePlayerView ytpv;
     private YouTubePlayer ytp;

     public void onCreate(Bundle savedInstanceState) {
          ...

          ytpv = (YouTubePlayerView) findViewById(R.id.youtube_view);
          ytpv.initialize("my_api_key_correctly_created", this); 
     }

     public void onInitializationFailure(Provider arg0, YouTubeInitializationResult arg1) {
          Toast.makeText(this, "Initialization Fail" + arg1.toString(), Toast.LENGTH_LONG).show();
     }


     public void onInitializationSuccess(Provider arg0, YouTubePlayer arg1, boolean arg2) {
          ytp = arg1;
          Toast.makeText(this, "Initialization  Success", Toast.LENGTH_LONG).show();

          if(ytp !=null)
          {
               ytp.loadVideo("ZvvgDC_MNqI");
          }
     }
}

我做错了什么?谢谢,对不起我的英语:)

What am I doing wrong? Thank you, and sorry my english:)

推荐答案

您是否尝试将跟踪"活动作为 TabHost 内的 ActivityGroup/TabActivity 的一部分启动?如果是这样,很遗憾 YouTubePlayerView 或 YouTubePlayerFragment 无法在 ActivityGroup 中初始化.由于 ActivityGroup 现在已弃用,我能给出的唯一建议是改用 Fragments.

Are you trying to start the 'Track' Activity as part of an ActivityGroup/TabActivity inside a TabHost? If so, unfortunately the YouTubePlayerView or YouTubePlayerFragment can't be initialized inside an ActivityGroup. Since the ActivityGroup is now deprecated, the only suggestion I can give is to use Fragments instead.

这篇关于Android Youtube Player Api - ERROR_CONNECTING_TO_SERVICE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)