gpt4 book ai didi

java - 视频完成后调用新 Activity

转载 作者:行者123 更新时间:2023-12-01 15:46:02 26 4
gpt4 key购买 nike

我正在尝试实现一个 onCompletionListener ,以便当启动视频完成时,调用选项卡 Activity (其中包含所有内容)。问题是,视频播放后,没有调用下一个 Activity 。代码如下:

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();
}

});
}
}

最佳答案

你能试试这个吗

 vs.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

public void onCompletion(MediaPlayer mp) {

splash.this.runOnUiThread(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
Intent main = new Intent(splash.this, tabhost.class);
splash.this.startActivity(main);
splash.this.finish();
}
});
}

编辑:也可以先注册监听器,然后再调用start吗?

 vs.start() 

关于java - 视频完成后调用新 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6983923/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com