我如何知道有人在我的Android应用上观看视频? [英] How do I know when someone's finished watching a video on my Android app?

查看:105
本文介绍了我如何知道有人在我的Android应用上观看视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!这是我对Code Project的第一个问题。



我正在制作Android应用程序。在其中一个活动中我播放视频。当一个视频结束时,第二个视频应该开始。



目前我的Java文件的这一部分播放了一个视频:

 @覆盖
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_watch);

VideoView vidView =(VideoView)findViewById(R.id.myVideo);

String vidAddress =https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512​​kb.mp4;
Uri vidUri = Uri.parse(vidAddress);

vidView.setVideoURI(vidUri);

vidView.start();
}





当这个视频结束时,我应该播放第二个视频。我可能会对视频进行编号,以便我可以对它们进行排序。



但我的问题是:

我怎么知道有人完成了什么看第一个视频?我不允许控件(如转发),以便他们不会跳过任何视频。但我不希望他们通过在第一个视频中间关闭应用程序来转到第二个视频。那么,我怎么知道他们什么时候完成了第一个视频,又怎么能动态改变正在播放的视频(例如video5.mp4)?

解决方案

Refer : setOnCompletionListener [ ^ ]

Hi! This is my first question on Code Project.

I'm making an Android app. In one of the activities I play videos. When one video ends, the second is supposed to start.

At the moment this part of my Java file plays one video:

@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_watch);
		
		VideoView vidView = (VideoView)findViewById(R.id.myVideo);
		
		String vidAddress = "https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4";
		Uri vidUri = Uri.parse(vidAddress);
		
		vidView.setVideoURI(vidUri);
		
		vidView.start();
	}



When this video ends I'm supposed to play the second one. I will probably number the videos so that I can sequence through them.

But my question is:
How can I know when someone's finished watching the first video? I don't allow controls (like forwarding) so that they don't skip any videos. But I don't want them to move on to the second video by closing the app halfway through the first video, for example. So, how can I know when they've finished the first video, and how can I dynamically change the video being played (e.g. video5.mp4)?

解决方案

Refer: setOnCompletionListener[^]


这篇关于我如何知道有人在我的Android应用上观看视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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