B4A Library User Aware Video View

This is a shortcut wrap for this Github posting. This wrapper is more about the concept that anything else. It allows you to play a video (mp4) from a URL and by making use of the front facing camera the app will determine if your eyes are focused on the video or not. If you eyes are indeed focused on the video then the video will play. If not, The app will automatically pause the video. Once you focus on the video again the video will automatically resume playing.

1.png



2.png

Have tested it on KitKat and Lollipop 5.1

The following applies:
1. You will need at least B4A V6.00
2. Min SDK = 15
3. You need to enable Appcompat V3.20 and DesignSupport V2.00 for this to work
Take note of the B4A manifest files
4. Attached the B4A library files, the Java code
5. This is a line to the other jars that you will require - download them and copy them to your additional library folder - https://www.dropbox.com/s/l14s509xl4g0dr3/UserAwareVideoOtherJars.zip?dl=0. You will also need them in the libs folder of a Java project if you want to compile the Java code
6. Download and extract folder UserAwareVideoRes.zip and copy the folder with its contents to be on the same folder level as that of the /Files and /Objects folders of the B4A project.
7. Download and extract folder resource.zip and copy the folder with its contents to be on the same folder level as that of the /Files and /Objects folders of the B4A project.
8. Once the video is "active" you can click on the video to make the controls appear.
9. Note that you might initially need an Internet connection so that some play services can be downloaded and installed. The play/pause will not work until such time as what these services are installed. But it does not take too long....

Sample code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aUserAwareVideoView
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\resource
#AdditionalRes: ..\UserAwareVideosRes


'#AdditionalRes: C:\Users\----------2\Documents\Basic 4 Android\JOHAN APPS\JHS LIBS\resource\b4a_appcompat, de.amberhome.objects.appcompat
'#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\v7\appcompat\res, android.support.v7.appcompat
'#AdditionalRes: C:\Android\extras\google\google-play-services\libproject\google-play-services_lib\res, com.google.android.gms
'#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\design\res, android.support.design

'#ExcludeClasses: .games, .drive, .ads, .fitness, .wearable, .measurement, .cast, .auth, .nearby
'#ExcludeClasses: .tagmanager, .analytics, .wallet, .plus, .gcm, .maps, .panorama

'#Extends: android.support.v7.app.AppCompatActivity

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
 

 
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Button1 As Button
    Dim uavw As UserAwareVideoView
 
 
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
 
    Activity.LoadLayout("main")
    uavw.Initialize("")
 
'    uavw.VideoURL = "http://clips.vorwaerts-gmbh.de/VfE_html5.mp4"
 
'    uavw.VideoURL = "http://techslides.com/demos/sample-videos/small.mp4"
 
    uavw.VideoURL = "http://www.html5videoplayer.net/videos/toystory.mp4"
 
End Sub

Sub Activity_Resume
 

 
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
 
uavw.Start_UAVW

End Sub

Manifest:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="22"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@style/MyAppTheme")
AddApplicationText(<meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

<meta-data
            android:name="com.google.android.gms.vision.DEPENDENCIES"
            android:value="face" />

        <activity
            android:name="sample.videoview.kevalpatel.com.userawarevideoview.MainActivity"
            android:icon="@drawable/icon"
            android:label="User Aware Video"
            android:theme="@style/Theme.AppCompat.NoActionBar"
            android:screenOrientation="fullSensor">

        </activity>) 
AddPermission(android.permission.CAMERA) ' Required to be able to access the camera device.     
AddPermission(android.permission.GET_TASKS)
AddPermission("android.hardware.camera")
AddPermission("android.permission.FLASHLIGHT")
 

Attachments

  • resource.zip
    423 bytes · Views: 204
  • TheJavaCode.zip
    12.6 KB · Views: 198
  • UserAwareVideoViewLibFiles.zip
    17.3 KB · Views: 211
  • b4aUserAwareVideoView.zip
    9.1 KB · Views: 197
  • UserAwareVideosRes.zip
    44.9 KB · Views: 190
Last edited:
Top