【问题标题】:How to move to another activity after a video is finished?视频完成后如何移动到另一个活动?
【发布时间】:2021-07-08 20:30:31
【问题描述】:

如果用户在视频播放完毕后返回主屏幕并返回应用程序,我正在尝试增加延迟时间。我希望应用程序移动到下一个活动。我该怎么做?

我当前的代码:

class MainActivity : AppCompatActivity() {
var currentp=0
var tmi:Long=7000
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        var inte= Intent(this,Main_menu::class.java)
        window.setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN
        )
        va.setBackgroundColor(Color.TRANSPARENT);

        val videoview : VideoView = va

        val uri = Uri.parse("android.resource://" + packageName + "/" + R.raw.intro)
        videoview.setVideoURI(uri)
        va.setZOrderOnTop(true)
        videoview.start()

        Handler().postDelayed({

    startActivity(inte)},7000)
}
     override fun onPause() {
        super.onPause()
currentp=va.currentPosition

     }

     override fun onStop() {
        super.onStop()
    }

    override fun onStart() {
        super.onStart()

    }

    override fun onResume() {
        super.onResume()
if(currentp!=0 && currentp!=100){
    va.seekTo(currentp)
        va.start()}
    }

【问题讨论】:

标签: android kotlin android-videoview


【解决方案1】:

JAVA

videoView.setOnCompletionListener(completionListener);
OnCompletionListener completionListener = new OnCompletionListener(){

        public void onCompletion(MediaPlayer mp) {
            Intent intent = new Intent(CurrentActivity.this, NextActivity.class);
            startActivity(intent); 
        }
    };

我通常用 Java 编写代码,但我尝试在 Kotlin 中进行转换,如果有问题请纠正我。

科特林

videoView.setOnCompletionListener{

            var intent = Intent(this, MainMenu::class.java)                
            startActivity(intent); 
        }
    };

现在您应该拥有一切可以走上正确的道路。干杯!

【讨论】:

  • 谢谢!虽然在 Kotlin videoview.setOnCompletionListener { var inte= Intent(this,Main_menu::class.java) startActivity(inte)} } 中是这样的,但谢谢你帮助我!
  • 不客气!我改变了它。感谢您的反馈!
猜你喜欢
  • 1970-01-01
  • 2013-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多