开发者

Calling New activity after video completes

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(saved开发者_C百科InstanceState);
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();
    }

});
}
}


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜