A VideoView that Detects your Face and Tracks your Eyes?

Pradyuman Dixit
AndroidPub
Published in
3 min readMar 4, 2019

--

How to know if the user is really watching your VideoView or not?

android wallpaper

Android is vast, with tons of possibilities and applications, there is no stopping to better and even better applications and libraries.

VideoView is one layout that is often used in the apps that have some kind of video being played on them. Whether it’s just an ad or an important course related video, VideoView is almost used every time.

But what if the user never bothered to really look at the video?

What if the student who was supposed to watch the video from home using mobile never watched it and the teacher could never understand why his student was not good at some concept?

What if the ad that was to be watched by the user was never really watched by the user and the app paid user the money they can earn by watching ads?

Yes, what if…

So this is something that really is an issue with VideoView.

You never know that the user really watched the video or just put the video on and went away to have a cheeseburger.

You never know if the user watched an ad or was just watching a web series on Netflix while your ad was being played.

So is there a way to have your VideoView know if the user really watched a video?

Of course there is, you can use Google Vision API. This is a very easy to use and amazing API by Google which can help you track face and trace eyes of the user.

You just need very few lines of code to do so and hence there is no issue of scaling or any stuff like that.

But is it really that easy?

Maybe you are not just in mood to code that all from scratch and read those boring API docs.

Well, LookAtMe has got your back.

LookAtMe logo

What is LookAtMe, you ask?

LookAtMe is an open source android library that easily provides you a VideoView that you can use to know if the user is watching or not.

LookAtMe has the video paused if the user has closed the eyes or the face is not detected.

So you can always know if the user watched the video or not, because if the video was finished, the video was watched because that’s how LookAtMe works.

But it would be hard to add this in your app, you say?

Lots of code…

Nope, not at all.

The whole of the code is present on my GitHub repository here.

You can easily add it in your android app.

You will find details for adding the library in your android app in the repository.

For using it, just add the following in your layout file of activity (XML):

<com.pd.lookatme.LookAtMe
android:id="@+id/lookme"
android:layout_width="match_parent"
android:layout_height="250dp" />

Configure your activity (java) code like this:

private LookAtMe lookAtMe;
lookAtMe = findViewById(R.id.lookme);
lookAtMe.init(this);lookAtMe.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.videoplayback));lookAtMe.start();
lookAtMe.setLookMe();

And yes, you’re all done. You’ve added a VideoView that only plays the video when the user is looking at the video.

So the result?

LookAtMe demo GIF

--

--