A customized video view that will automatically pause video is user is not looking at device screen!!!!!

Overview

UserAwareVideoView

Build Status Download Hex.pm API

Featured in:

What is this library for?

UserAwareVideoView is a customizable VideoView that smartly play and pause the video based on your user is looking at the video or not. This uses Play Services Mobile Vision APIs to detect user's eyes. If the user is not looking at the screen than this will automatically pause the video, so your user does not miss any part of the video.

How to use this library???

Gradle dependency:

Add these lines to your build.gradle file to start integration.

dependency{
    compile 'com.kevalpatel2106:userawarevideoview:1.0.2'
}
  • This library automatically adds android.permission.CAMERA permission in your applications AndroidManifest.xml file.

Add to XML layout:

You can use UserAwareVideoView just like you user the default VideoView in your layout.

 <com.kevalpatel.userawarevieoview.UserAwareVideoView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/video_view"/>

Initialize in your activity:

  • Step-1: Check for the Camera permission in runtime.
  • Step-2: Register UserAwarenessListener to get the callbacks from the UserAwareVideoView whenever error occurs in eyes detection or eye detection starts stops.
  • Step-3: Handle errors that may occur while eyes detection.
mVideoView = (UserAwareVideoView) findViewById(R.id.video_view);
mVideoView.setUserAwarenessListener(new UserAwarenessListener() {
            @Override
            public void onErrorOccurred(int errorCode) {
                //Handle errors.
                 switch (errorCode) {
                            case Errors.UNDEFINED:
                                //Unknown error occured. 
                                //This will stop eye tracking, but video will keep playing.
                                break;
                            case Errors.FRONT_CAMERA_NOT_AVAILABLE:
                                //This indicates that device doesnot have the front camera
                                //This will stop eye tracking, but video will keep playing.
                                break;
                            case Errors.CAMERA_PERMISSION_NOT_AVAILABLE:
                                //This indicates that camera permission is not available.
                                //Ask for the runtime camera permission.
                                break;
                            case Errors.LOW_LIGHT:
                                //This indicates that there is dark out side. We cannot detect user's face.
                                //This will stop eye tracking, but video will keep playing.
                                break;
                        }
            }

            @Override
            public void onEyeTrackingStarted() {
                //Eye detection started
            }

            @Override
            public void onEyeTrackingStop() {
                //Eye detection is stopped.
            }
        });
//Atatch your media controller, provide video to play and start the video
//......
//......

That's it. UserAwareVideoView is ready to use.

Demo

  • You can download the sample apk from here.
  • The video in sample apk is streamed online. So, make sure you have active internet connection.

Contribute:

Simple 3 step to contribute into this repo:

  1. Fork the project.
  2. Make required changes and commit.
  3. Generate pull request. Mention all the required description regarding changes you made.

Questions

Hit me on twitter Twitter

License

Copyright 2017 Keval Patel

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

You might also like...
CheckInternetConnection - CheckInternetConnection helps to find out if user`s Android device is connected to Internet or not

Check Internet Connection CheckInternetConnection helps to find out if user`s An

Events Calendar is a user-friendly library that helps you achieve a cool Calendar UI with events mapping. You can customise every pixel of the calendar as per your wish and still achieve in implementing all the functionalities of the native android calendar in addition with adding dots to the calendar which represents the presence of an event on the respective dates. It can be done easily, you are just a few steps away from implementing your own badass looking Calendar for your very own project! Android library to auto-play/pause videos from url in recyclerview.
Android library to auto-play/pause videos from url in recyclerview.

AutoplayVideos Show some ❤️ and star the repo to support the project This library is created with the purpose to implement recyclerview with videos ea

PlayPauseDrawable 1.9 0.0 L5 Java This is a sample Play & Pause Drawable with morphing animation for Android
PlayPauseDrawable 1.9 0.0 L5 Java This is a sample Play & Pause Drawable with morphing animation for Android

#PlayPauseDrawable #Deprecated please go to https://github.com/tarek360/Material-Animation-Samples This is a sample Play & Pause Drawable with morphin

Material style morphing play-pause drawable for Android
Material style morphing play-pause drawable for Android

Play There is no need to explain what this thing does, just take a look at the gif below. Including in your project Add to your root build.gradle: all

Android 12 beta bug activity doesnt pause
Android 12 beta bug activity doesnt pause

android-12-beta-bug-activity-doesnt-pause Tracker link: https://issuetracker.google.com/u/1/issues/202616720 The issue: clicking the "Recent" button o

Just a simple tool to turn on/off DND(Do Not Disturb) automatically when using specified apps.
Just a simple tool to turn on/off DND(Do Not Disturb) automatically when using specified apps.

AutoDND Just a simple tool to turn on/off DND(Do Not Disturb) automatically when using specified apps. Ever feel disturbed by notifications and maybe

A circular android ProgressBar library which extends View,  and the usage same as ProgressBar,  It has solid,line and solid_line three styles. Besides, progress value can be freely customized.
A circular android ProgressBar library which extends View, and the usage same as ProgressBar, It has solid,line and solid_line three styles. Besides, progress value can be freely customized.

CircleProgressBar 中文版文档 The CircleProgressBar extends View, It has both solid and line two styles. Besides, progress value can be freely customized. I

[Development stopped in 2014. Unfinished and not stable - not recommended to use.] An easy-to-use ViewPager subclass with parallax background effect for Android apps.

Development stopped in 2014 Not developed since 2014. Unfinished and not stable - not recommended to use. ParallaxViewPager An easy-to-use ViewPager s

 AutoPlayer - A player based on ExoPlayer for play video automatically in RecyclerView, when an item is visible.
AutoPlayer - A player based on ExoPlayer for play video automatically in RecyclerView, when an item is visible.

A player based on ExoPlayer for play video automatically in RecyclerView, when an item is visible.

This is an Image slider with swipes, Here we used Volley to Image load URL's from JSON! Here we make it very easy way to load images from Internet and We customized the description font style(OpenSans).

ImageSliderWithSwipes This is an Image slider with swipes, Here we used Volley to load URL's from JSON! Here we make it very easy way to load images f

Arc pointer - simple customized progress bar in the form of an arch
Arc pointer - simple customized progress bar in the form of an arch

ArcPointer Simple customized progress bar in the form of an arch Demo Quick start Step 1 Gradle: compile 'io.github.dvegasa:arcpointer:1.0.2' Maven:

This library allows to use customized Rating Dialog inside applications.
This library allows to use customized Rating Dialog inside applications.

Android Material App Rating This library allows to use customized Rating Dialog inside applications. Download compile 'com.stepstone.apprating:app-rat

Customized and RoundedEditText
Customized and RoundedEditText

CustomEditText A Collection of features are wrapped into single UI element. By adding a line code in xml, able to access these features,rectangular vi

Customized and Expandable TextView
Customized and Expandable TextView

Customized and Expandable TextView Simple library to change the Textview as rectangle, circle and square shapes by adding one line of code in xml file

An android library through which users can add a customized loading dialog box with Lottie Animations.
An android library through which users can add a customized loading dialog box with Lottie Animations.

CustomLottieDialogBox About CustomLottieDialogBox is an android library which facilitate developers to add customized loading Dialog-Boxes to their an

Highly customized vertical Seekbar with segments
Highly customized vertical Seekbar with segments

SegmentedVerticalSeekBar It is an Android Vertical Seekbar with segments develop

My Maps displays a list of maps, each of which show user-defined markers with a title, description, and location. The user can also create a new map. The user can save maps and load them in from previous usages of the app.

My Maps Bryant Jimenez My Maps displays a list of maps, each of which show user-defined markers with a title, description, and location. The user can

Comments
  • Crash in sample apk

    Crash in sample apk

    i appreciate your work buddy. i downloaded you sample apk and install it in 3-4 phones and unfortunately app is crashing. in one phone says front camera not deteted/found even device has front camera in another phone it says unable to detect your eyes.

    can you fix these so that i can enjoy it.

    bug 
    opened by android-rk 12
  • Device does not have front camera....

    Device does not have front camera....

    I have downloaded the APK. On my Samsung S4 mini with Kitkat it displays the message "Device does not have front camera..." even though the video plays/pauses when I look at/look away from the front facing camera. Also happens on my Vodaphone with Lollipop 5.1

    Other than this - a great project!

    opened by johan-schoeman 4
  • Cannot inflate dialog with UserAwareVideoView

    Cannot inflate dialog with UserAwareVideoView

    Hi, I have a custom Dialog in my Android App that has a video asset that plays at the top. It works fine with a VideoView, however when I replace the video view with your view, I get a runtime error.

    The following is the error in my XML:

    java.lang.RuntimeException: Cannot initialize with other than Activity context. at com.kevalpatel.userawarevieoview.UserAwareVideoView.init(UserAwareVideoView.java:75) at com.kevalpatel.userawarevieoview.UserAwareVideoView.<init>(UserAwareVideoView.java:47) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:465) at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:172) at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105) at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:186) at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:334) at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:345) at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:245) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70) at android.view.LayoutInflater.rInflate(LayoutInflater.java:834) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.inflate(LayoutInflater.java:518) at android.view.LayoutInflater.inflate(LayoutInflater.java:397) at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:324) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429) at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389) at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:548) at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:533) at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:966) at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533) at com.android.tools.idea.rendering.RenderTask.lambda$inflate$53(RenderTask.java:659) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

    And this is the error that I get during runtime:

    android.view.InflateException: Binary XML file line #6: Binary XML file line #6: Error inflating class com.kevalpatel.userawarevieoview.UserAwareVideoView

    What can I do to make this work in my context?

    enhancement 
    opened by phundal209 1
Releases(1.0.2)
Owner
Keval Patel
Android Dev | Open source contributor
Keval Patel
A simple screen starter written in kotlin

screen-starter A simple screen starter written in kotlin. Compilation Use clean shadowJar! Usage Use java -jar screen-starter-1.0-SNAPSHOT.jar --confi

GrowlyX 3 Sep 1, 2021
Android App development internship project to create woman home screen for clothing company The Swastika.

Android App development internship project to create woman home screen for clothing company The Swastika.

Shradha Suryawanshi 2 Jun 12, 2022
SL4A brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device.

#Scripting Layer for Android (SL4A) SL4A brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreter

Damon Kohler 2.3k Dec 23, 2022
Use your old Android device as an OctoPrint server.

Use your old Android device as an OctoPrint server.

Feelfree (Filip) 1k Dec 31, 2022
Cache support for any video player with help of single line

Video cache support for Android Table of Content Why AndroidVideoCache? Features Get started Recipes Disk cache limit Listen caching progress Providin

Alexey Danilov 5.1k Jan 6, 2023
Menyimpan source code tugas User Interaction and Control, mata kuliah Pemrograman Mobile Teori, semester lima tahun 2021.

android-uic About This Project Android-uic adalah sebuah aplikasi sederhana yang dibuat untuk menyelesaikan tugas dua mata kuliah pemrograman mobile.

Galang Aidil Akbar 1 Nov 8, 2021
Recruitment Task App - record time which a user spends on tasks defined by himself

Recruitment-Task The purpose of this application is to record time which a user spends on tasks defined by himself. The user can add new tasks. New ta

Sylwester Zieliński 0 Feb 9, 2022
AudioPlayerView is an Android view that loads audio from an url and have basic playback tools.

AudioPlayerView AudioPlayerView is an Android view that loads audio from an url and have basic playback tools. It makes use of the Android MediaPlayer

Hugo Matilla 86 Nov 29, 2022
A special view that can contain other views (called children)

A ViewGroup is a special view that can contain other views (called children.) The view group is the base class for layouts and views containers. There

Phạm Thành Trung 1 Oct 16, 2021
Native Device security checks, Rooted/Jailbroken, Not real device, Developer mode is on, On external drive.

palestine_trusted_device Native Device security checks, Rooted/Jailbroken, Not real device, Developer mode is on, On external drive. Part of Palestine

Palestine Developers 3 Apr 19, 2022