0

我正在学习 android,我试图弄清楚如何在视频视图完成后打开一个新场景。

这是我的代码:

import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.VideoView;

public class SplashScene extends Activity implements OnCompletionListener {

    BaseActivity activity;
    VideoView video;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.splash);

        video = (VideoView) findViewById(R.id.vvSplashVideo);
        String path = "android.resource://" + getPackageName()
                + "/raw/splashscreen";
        video.setVideoURI(Uri.parse(path));

        video.setOnCompletionListener(this);

        video.start();
        loadResources();
    }

    public void loadResources() {


    }

    @Override
    public void onCompletion(MediaPlayer arg0) {
        // TODO Auto-generated method stub


        Log.v("Fin", "done");

        activity.setCurrentScene(new MainMenuScene());      
    }

当我运行该应用程序时,视频有效并且日志消息有效,但随后出现此错误:

http://puu.sh/1YuiA在应用程序崩溃之前。

关于我做错了什么的任何想法。

4

1 回答 1

0

activity;您必须在 SplashScene 类中进行初始化。

代码:

public class SplashScene extends Activity implements OnCompletionListener {

BaseActivity activity;
....

 @Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

activity=new BaseActivity (); <===== initiate this

// rest of code } 

}

}

于 2013-02-07T12:38:38.587 回答