我自己实现了一个 OnCompletionListener,如下所示:
public class SongEndCompletionListener implements OnCompletionListener{
String nextView;
Context actualActivity;
int stopTime;
public SongEndCompletionListener(Context activity, String nextView, int time) {
this.nextView = nextView;
actualActivity = activity;
}
@Override
public void onCompletion(MediaPlayer arg0) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
try {
Intent stopplay;
stopplay = new Intent(actualActivity,Class.forName(nextView));
actualActivity.startActivity(stopplay);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}, stopTime);
}
}
我希望它暂停 stopTime 秒,但它实际上是在音频文件结束后立即跳转到下一个视图。您能否指出我错在哪里或如何以不同的方式延迟切换到另一个活动?
每一个提示都值得赞赏!