视频完成后调用新活动
我正在尝试实现一个 onCompletionListener ,以便当启动视频完成时,调用选项卡活动(其中包含所有内容)。问题是,视频播放后,没有调用下一个活动。这是代码:
package com.companyname.cpny;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.widget.VideoView;
public class splash extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView vs = (VideoView) findViewById(R.id.imlsplash);
Uri uri = Uri.parse("android.resource://"+getPackageName() + "/"+R.raw.iphonesplashfinal);
vs.setVideoURI(uri);
vs.start();
vs.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
Intent main = new Intent(splash.this, tabhost.class);
splash.this.startActivity(main);
splash.this.finish();
}
});
}
}
I am trying to implement an onCompletionListener so that when the splash video completes, the tab Activity ( where all the content is contained) is called. The problem is, after the video plays, the next activity is not called. Here's the code:
package com.companyname.cpny;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.widget.VideoView;
public class splash extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView vs = (VideoView) findViewById(R.id.imlsplash);
Uri uri = Uri.parse("android.resource://"+getPackageName() + "/"+R.raw.iphonesplashfinal);
vs.setVideoURI(uri);
vs.start();
vs.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
Intent main = new Intent(splash.this, tabhost.class);
splash.this.startActivity(main);
splash.this.finish();
}
});
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以尝试这个
编辑:
也可以先注册监听器,然后再调用start吗?
Can you try this
EDIT:
Can you also register the listener first and call start later.