当视频播放完毕开始活动 [英] Starting Activity when video is finished playing

查看:124
本文介绍了当视频播放完毕开始活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序,我想简单地回到我的主要活动一次,我打端视频。我已经尝试了很多解决方法,但我不能找到一个方法来调用StartActivity从视频onCompletionListener - 我得到了不能让从类型活动的静态引用非静态方法startActivity(意图)的错误

In my Android app, I am trying to simply go back to my main Activity once a video that I am playing ends. I have tried many workarounds, but I can't find a way to call StartActivity from the video onCompletionListener - I am getting the "cannot make a static reference to the non-static method startActivity(Intent) from the type Activity" error.

我试图从preceded的videoView活动得到一个上下文,并递过来的意图/ startActivity。这让应用程序编译,但后来我得到了一个运行时异常。

I tried getting a context from the Activity that preceded the videoView, and passing that to the intent/startActivity. That allowed the app to compile, but then I got a runtime exception.

下面是code因为目前的情况是,它得到了不能让一个静态引用的错误 - !任何帮助将是AP preciated

Here is the code as it stands now, which gets the "cannot make a static reference" error - any help would be appreciated!

public class Videoscreen extends Activity{

public static VideoView myVideoView;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.videoplay);
    myVideoView = (VideoView) findViewById(R.id.main_videoview);
    System.out.println("playing video oncreate");
    playVideo();
}
public static void playVideo(){

    // video finish listener
    myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer vmp) {
            Intent intent = new Intent();
            intent.setClass(Videoscreen.this, Game.class);
            Videoscreen.startActivity(intent);
        }
    }); 

    String low_word = SpellingView.get_low_word();
    Uri bubblesUri = Uri.parse("android.resource://org.lalloinc.ilovetrucks/raw/"+ low_word + "_vid");
    myVideoView.setVideoURI(bubblesUri);
    myVideoView.start();

}

}

推荐答案

如果您从活动开始的视频活动,你想回去以后,只调用完成()在视频的结尾将做的工作

If you started the Video Activity from the Activity you would like to go back to later, just calling finish() at the end of the video will do the job.

启动主要活动再次创建一个不一定要栈的活动。

Starting the main Activity again creates a not necessarily wanted stack of activities.

这篇关于当视频播放完毕开始活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆