请忍受我,因为我是相当新的Android.我正试图在片段类初始化YouTube播放器.谷歌已经提供了方法来初始化活动如下:
package com.examples.youtubeapidemo;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
import android.os.Bundle;
public class PlayerViewDemoActivity extends YouTubeFailureRecoveryActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playerview_demo);
YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
boolean wasRestored) {
if (!wasRestored) {
player.cueVideo("wKJ9KzGQq0w");
}
}
@Override
protected YouTubePlayer.Provider getYouTubePlayerProvider() {
return (YouTubePlayerView) findViewById(R.id.youtube_view);
}
}
字符串
我试着使用这个代码,但它不工作:
public class TabFragment5 extends YouTubePlayerFragment implements YouTubePlayer.OnInitializedListener {
/** (non-Javadoc)
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
*/
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null) {
return null;
}
YouTubePlayerFragment yf = newInstance(); //new YouTubePlayerFragment();
yf.initialize("dsds", this);
return (LinearLayout)inflater.inflate(R.layout.tab_frag4_layout, container, false);
}
@Override
public void onInitializationFailure(Provider arg0,
YouTubeInitializationResult arg1) {
// TODO Auto-generated method stub
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
boolean wasRestored) {
if (!wasRestored) {
player.cueVideo("nCgQDjiotG0");
}
}
}
型
如果有人能为fragment提供等效的API,我将不胜感激。
1条答案
按热度按时间pb3s4cty1#
试着用下面的例子:
fragment.xml
字符串
片段创建
型
视频片段
型