视频完成后调用新活动

发布于 2024-11-29 00:13:40 字数 1065 浏览 0 评论 0原文

我正在尝试实现一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉宸 2024-12-06 00:13:40

你可以尝试这个

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

Can you try this

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

EDIT:
Can you also register the listener first and call start later.

 vs.start() 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文