How to show Front Camera Preview on Framelayout using Camera2 in Android? - android

I am working in one application, In which I am using tokbox for the video calling, But before displaying the Active call screen, I need to show the front camera preview to the user. Using tokbox publisher we can't do that otherwise, the video will reach the end user before call accept.
So How can we show Front Camera Video preview(Just the preview, I don't need any capturing or anything) in the framelayout using Camera2 API of Android?

You can get a preview from the Publisher by calling Publisher.startPreview(). This will start the camera and put it on the Publisher.getView() that you can put in your UI.
Don't forget to do Publisher.destory() if you do this. I didn't do that at first and noticed issues of the camera not being released correctly after TokBox sessions on older (non-Camera2) devices.

You can use instantiate the publisher and use it's view, and not publish to the session initially.

Related

How to programmatically stop a screen video recorder from recording an Android app

I don't want anyone to use a screen recording app on their Android phone to VIDEO record my app's screen. I know screen capture can be prevented, but what about video?
By adding FLAG_SECURE into your Activity You can secure screen capturing functionality
getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
write above setContenView();
from documentation
Android 5.0 lets you add screen capturing and screen sharing
capabilities to your app with the new android.media.projection APIs.
This functionality is useful, for example, if you want to enable
screen sharing in a video conferencing app.
The new createVirtualDisplay() method allows your app to capture the
contents of the main screen (the default display) into a Surface
object, which your app can then send across the network. The API only
allows capturing non-secure screen content, and not system audio. To
begin screen capturing, your app must first request the user’s
permission by launching a screen capture dialog using an Intent
obtained through the createScreenCaptureIntent() method.
and Also from this documentation says
Window flag: treat the content of the window as secure, preventing it
from appearing in screenshots or from being viewed on non-secure
displays.
NB
If you are using SurefaceView with media player then use SurfaceView.setSecure(true), then your video will be secured from any other apps.

Video Recording with Mobile Vision face detection

I am building a app where i am using mobile vision sdk for face detection and showing some overlay on face. but i am facing problem while record video. Is there any solution to record video with same problem.
Thanks
Since Android 5.0 there is a new API that can be used for screen recording: MediaProjection. The MediaProjection grants the ability to capture screen content, but not system audio. Also it won't capture secure screen content. You need user permission for capturing the screen. Please refer to this for screen recording.
Screen Video Record of Current Activity Android

How to setup camera preview with camera2 API for both photo and video at once?

My app provides a camera, which allows user to either take a picture or record a video. I have no possibility to know which action user is going to choose. So I need to provide camera preview for both actions. With old camera API there was no problem at all, but I'm not sure about camera2 API.
I have thoroughly looked through both Google examples: Camera2Basic and Camera2Video, and I noticed that for taking pictures the preview builder uses CameraDevice.TEMPLATE_PREVIEW:
mPreviewRequestBuilder = mCameraDevice.createCaptureRequesT(CameraDevice.TEMPLATE_PREVIEW);
For Video recording it uses CameraDevice.TEMPLATE_RECORD;
mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
I have checked the descriptions for all templates in CameraDevice class, but still am not sure what is the right way in my case. I have tried to set TEMPLATE_PREVIEW for video recording, and it worked ok, but do I understand it correctly that in this case the quality of the video may be lower? Cause in docs it says the following:
Specifically, this means that high frame rate is given priority over the highest-quality post-processing.
The templates just have default values for the various CaptureRequest settings. Each template is aimed at some specific use case.
But for simplicity, TEMPLATE_PREVIEW for preview before you start recording should be fine; I'd recommend switching to TEMPLATE_RECORD while actually recording. Then switch back to TEMPLATE_PREVIEW once the user stops recording.

Prevent other applications form capturing/recording screen

Basically i want VIDEO PIRACY PROTECTION
My application has video streaming and I want to protect my video streaming from other applications. Other applications should not be able to capture screen while my video is playing. Any suggestions how can i achieve this.. Thanks in advance.
You can secure screen capturing functionality by adding FLAG_SECURE into your Activity as follows
getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
Check this link which says
Screen capturing and sharing
Android 5.0 lets you add screen capturing and screen sharing
capabilities to your app with the new android.media.projection APIs.
This functionality is useful, for example, if you want to enable
screen sharing in a video conferencing app.
The new createVirtualDisplay() method allows your app to capture the
contents of the main screen (the default display) into a Surface
object, which your app can then send across the network. The API only
allows capturing non-secure screen content, and not system audio. To
begin screen capturing, your app must first request the user’s
permission by launching a screen capture dialog using an Intent
obtained through the createScreenCaptureIntent() method.
Also documentation at this link says that
Window flag: treat the content of the window as secure, preventing it
from appearing in screenshots or from being viewed on non-secure
displays.
Above solution will surely prevent applications from capturing Video of your app
getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
write above setContenView();
It prevents only snapshot capturing. And also prevents video capturing. But For video capturing its device specific.
Try adding this in your Activity,
getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);

how to capture video without showing the camera window or program

i want to capture in android programming without showing the camera
only want to have two button, by clicking first button, it start capturing and by clicking the second, capturing will be stop and save the file somewhere in phone.
also saw this link Video Recording and Image Capture on Android using Camera Intents
its first week that i started android programming, thanks for your helps
There are two ways to capture videos on Android.
The first way is to use an Intent (a message) to ask applications able to capture video to start and to capture the video for you.
The second way is to build your own video recorder.
The first option is not suitable for you, as you will not be able to control the display of the called application.
Concerning the second option, there is a great tutorial on the official website about how to develop a camera application. Here is the link Camera App tutorial. Basically you will want to look to the part called "Building a Camera App" and "Capturing video". As you will see through the tutorial they use a SurfaceView (which you put in your layout just as any other view) to display the camera content. You can just follow the tutorial and then set the visibility of the view to false. Or, if you're more confident, you can try to skip part using the surfaceview.
Hope i could help !

Categories

Resources