的Android YouTube播放器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密钥我使用的是正确的(因为它工作正常,在谷歌演示)。
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;
CLASSE定义:
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:)
推荐答案
您尝试启动轨道活动作为的ActivityGroup / TabActivity内TabHost的一部分?如果是这样,可惜YouTubePlayerView或YouTubePlayerFragment不能在里面的ActivityGroup初始化。由于的ActivityGroup现在是很precated,唯一的建议我可以给是使用片段来代替。
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播放器API - ERROR_CONNECTING_TO_SERVICE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!