我開發的android youtube api.i成功創建了youtube api項目,並且我可以在活動開始時播放youtube視頻。現在我想播放視頻只在按鈕click.i有nullpointexception 這是我的代碼Android Youtube Api nullPointException
public class MainActivity extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener {
static private final String DEVELOPER_KEY = "************";
static private final String VIDEO = "hjHnWz3EyHs";
private Button b1;
private YouTubePlayer player;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
b1 = (Button) findViewById(R.id.button1);
youTubeView.initialize(DEVELOPER_KEY, this);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
player.loadVideo(VIDEO, 36000); //error is in this line
}
});
}
@Override
public void onInitializationFailure(Provider provider,
YouTubeInitializationResult error) {
Toast.makeText(this, "Oh no! " + error.toString(), Toast.LENGTH_LONG)
.show();
}
@Override
public void onInitializationSuccess(Provider provider,
YouTubePlayer player, boolean wasRestored) {
//player.loadVideo(VIDEO, 36000);
}
} 什麼是錯的?如果有人知道解決方案,請幫助我 謝謝
刪除按鈕單擊該行並刪除'onInitializati中的註釋onSuccess'它會工作。這個實例可放大的播放器永遠不會初始化 – Raghunandan