Android Youtube Player Api - ERROR_CONNECTING_TO_SERVICE

匿名 (未验证) 提交于 2019-12-03 01:06:02

问题:

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

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

Imports:

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; 

Classe definition:

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:)

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!