我有一项活动来显示来自youtube的视频列表。单击某个项目时,它将使用以下代码播放视频。但在紧急情况下没有任何反应。谁能告诉我如何回到以前的活动?
public class VideoPlayer extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {
private String videoId;
private static final int REQ_START_STANDALONE_PLAYER = 1;
private final static String DBUG = VideoPlayer.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
Intent in = getIntent();
videoId = in.getStringExtra("videoId");
System.out.println("VideoId received :::"+videoId);
Intent intent = YouTubeStandalonePlayer.createVideoIntent(this, Constants.DEVELOPER_KEY, videoId,0,false,false);
startActivityForResult(intent, 1);
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
Log.v(DBUG, "Back has been pressed::");
finishActivity(REQ_START_STANDALONE_PLAYER);
finish();
}
}
答案 0 :(得分:1)
private String videoId;
private final static String DBUG = VideoPlayer.class.getSimpleName();
private YouTubePlayerView youtuber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
Intent in = getIntent();
videoId = in.getStringExtra("videoId");
System.out.println("VideoId received :::"+videoId);
youtuber = (YouTubePlayerView) findViewById(R.id.youtube_view);
youtuber.initialize(Constants.DEVELOPER_KEY, this);
}
@Override
public void onInitializationSuccess(Provider arg0, YouTubePlayer arg1,
boolean arg2) {
// TODO Auto-generated method stub
Log.v(DBUG, "Playing video");
arg1.cueVideo(videoId);
}
答案 1 :(得分:0)
尝试将onBackPressed()改为onKeyDown():
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.v(DBUG, "Back has been pressed::");
finishActivity(REQ_START_STANDALONE_PLAYER);
finish();
return true;
}