LiveHiddenCamera - Library Which Record Live Video And Audio From Android Device Without Displaying A Preview

Live Hidden Camera (LHC) is a library which record live video and audio from Android device without displaying a preview.

How to use
I've created a library to make it more usable. The only requirement is to add the library to your project and pass the Rtmp URL to it.
Additionally you should care about:
  1. Your application should have the following permissions in Manifest.xml:
  • <uses-permission android:name="android.permission.INTERNET" />
  • <uses-permission android:name="android.permission.CAMERA" />
  • <uses-permission android:name="android.permission.RECORD_AUDIO" />
  • <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
  1. You should handle that the declared permissions are granted to your application

Adding library
The usage of the library is straight. Just add the following library to the gradle.build file of your project.
compile 'ir.mstajbakhsh.android:LiveHiddenCamera:0.1.0'

Creating RTMP server
Before using the library, you should have deployed an Rtmp server. I've ued Ant Media Server. There is a nice guide on Ant Media Server installation in THIS LINK.
After starting the Ant Media RTMP server, you should see something like this:

Sample Code
After adding the library to your project, do the following steps:
  1. Create a class which implements: RtmpHandler.RtmpListener, SrsRecordHandler.SrsRecordListener, SrsEncodeHandler.SrsEncodeListener
  2. Create two fields (one for publish and one for preview):
    private SrsPublisher mPublisher;
    private SrsCameraView mCameraView;
  3. Implement a function for starting the Live Hidden Camera:
    private void initHiddenCam(String rtmpURL) {  
HiddenCameraLayout l = new HiddenCameraLayout(getApplicationContext(), new HiddenCameraLayout.PermissionHandler() {
public void onPermissionNotGrantedException(Exception ex) {
Log.d("HCL", "Ask user to grant permission.");
Log.e("HCL", ex.getMessage());

//start config
CameraConfig cameraConfig = new CameraConfig()

mCameraView = l.initHiddenLayout(cameraConfig);

mPublisher = new SrsPublisher(mCameraView);
mPublisher.setEncodeHandler(new SrsEncodeHandler(this));
mPublisher.setRtmpHandler(new RtmpHandler(this));
mPublisher.setRecordHandler(new SrsRecordHand ler(this));
mPublisher.setPreviewResolution(640, 360);
mPublisher.setOutputResolution(640, 360);

You can reach me from my website: https://mstajbakhsh.ir/

Disqus Comments