B4A Library [B4A] [B4XPages] ScreenRecorder/ScreenShots

B4A B4XPages ScreenRecorder - version 0.7 (25/09/2016)

25/01/2021 - Updated the sample app to use SDK29, foreground services, and also wrote it as a B4XPages app. There are no changes to the library.


Here is a wrapper/library which lets you record the screen and save it as a video file.

It is using MediaProjection which is available from API 21 (Lollipop) and will not work on earlier versions of Android.

It is based on this Github-project. Kudos to the original author.

See next post for events and methods.

I am attaching a sample project along with the library.

Edit: The free version posted here is OK for screen-recording. There is also a more advanced version of this library which enables screen-recording with audio, capturing screenshots and screen-mirroring. Send me a PM (start a conversation) if you are interested.

Some basic stuff to remember:
1) you need at least Lollipop to get this to work. The library uses MediaProjection which was introduced with SDK 21.
2) You cannot use it for a spy-app. When users run your app and the code in your app which triggers the screen-capturing (recording or screenshots), users have to give permission.
3) some apps, such as Telegram, can block MediaProjection, and thus capturing/recording of the screen is not possible.


Please remember that creating libraries and maintaining them takes time and so does supporting them. Please consider a donation if you use my free libraries as this will surely help to keep me motivated. Thank you!
 

Attachments

  • B4AScreenRecorderLibs.zip
    7.9 KB · Views: 1,089
  • B4XPagesScreenRecorder.zip
    12.5 KB · Views: 384
Last edited:

moster67

Expert
Licensed User
I get some questions about the advanced version so here is some information:

The free version posted here is OK for screen-recording. There is also a more advanced version of this library which enables screen-recording with audio and capturing screenshots. The advanced version of this library is still a work in progress but users who have bought it are already using it in their apps. At this point of development, the price is EUR 15,00 for the advanced version but it will probably be more when it's ready.
Send me a PM (start a conversation) if you are interested.
 

Neojoy

Member
Licensed User
Very cool!!!

The advanced version needs permission like free version and can I run under a service?

Another question, it works in web or only in local network?

Thanks!
 

moster67

Expert
Licensed User
hi again, sorry for asking again but is it possible to record audio when recording the screen?
Yes, the audio can be recorded in the advanced version. Only microphone though since system-audio cannot be recorded on Android at all.
 

ilan

Expert
Licensed User
Yes, the audio can be recorded in the advanced version. Only microphone though since system-audio cannot be recorded on Android at all.

great and how can i get the advanced version?
 

DonManfred

Expert
Licensed User
great and how can i get the advanced version?
The free version posted here is OK for screen-recording. There is also a more advanced version of this library which enables screen-recording with audio and capturing screenshots. The advanced version of this library is still a work in progress but users who have bought it are already using it in their apps. At this point of development, the price is EUR 15,00 for the advanced version but it will probably be more when it's ready.
Send me a PM (start a conversation) if you are interested.
 

Syd Wright

Well-Known Member
Licensed User
Can this screen recorder also capture screen shots as BMP of JPG bitmaps (at pre-determined intervals) in stead of as video?
 

moster67

Expert
Licensed User
Can this screen recorder also capture screen shots as BMP of JPG bitmaps (at pre-determined intervals) in stead of as video?
If you have a look at the screen-mirroring video, you can see that numerous screenshots are captured within a second (see the log-pane). The responsible method is run within a service. Note that the OS decides when to send new images via the ImageReader.OnImageAvailableListener interface (included in my library). This is the reason why sometimes images are being captured less frequently (few updates) on a stale Activity. If there are movements, the OS sends more images.

This is the API-description of the method concerned:

Call StartShooting() to start a session of taking continuous screenshots. You can save the images
as a file or return them as a Bitmap.
You can then monitor the Result-event if each capture was successful or not.

1) Saving screenshots as image-files:
You need to indicate in which image format you want your pictures saved in. You can
choose between the following formats: JPEG, PNG and WEBP (use available constants).
You must also set the ImageQuality (int range 1 - 100). If the value is not within the range, the value of
100 (max quality, bigger file-size) will be used.
You also need to indicate where you want to save your images and which file-name to give them. The
library will automatically add a number-suffix to the file-name. The image extension will be appended
automatically to the file-name according to which image format you used. With the last parameters, MaxImages,
you set how many pictures will be captured before the oldest are deleted. This is to avoid that you fill up your
storage with hundreds of pictures.
Example usage:
scr.StartShooting(scr.JPEG, 75, File.DirRootExternal, "im", 50)

2) Returning screenshots as a Bitmap:
Use the constant BITMAP as a parameter for imageFormat, add a number(int) for imageQuality and
add empty strings ("") to the parameters dirPath and fileName and a casual number (int) for the
maxImages parameter. Then monitor the Result-event and if the Success-value is true, a Bitmap object was retrieved
which you can get from the BitmapRetrieved object otherwise no Bitmap was retrieved. Please note that no
compression is applied to Bitmaps. They are passed on in original quality.
Example usage:

Dim myBitmap as Bitmap
scr.StartShooting(scr.BITMAP, 75, "", "", 1)
Sub scr_Result(Success as Boolean) 'event
if Success = true then
myBitmap = scr.BitmapRetrieved
else
log("Error obtaining bitmap")
end if
End Sub
 

Syd Wright

Well-Known Member
Licensed User
Thank you. Yes I already watched this video. Is it possible to set the frequency at which frames are captured (e.g. 1 to 10 fps)?

I am planning to make a (TV and video) subtitles reader for blind people (no need to capture sound).
Johann Schoemann's OCR looks very promissing for this purpose.

Do I need the advanced version of your library for this purpose (I assume yes) and is it ready/stable enough for the application I intend to build?
 
Last edited:

moster67

Expert
Licensed User
Is it possible to set the frequency at which frames are captured (e.g. 1 to 10 fps)?
You cannot set the frequency. As mentioned above:
Note that the OS decides when to send new images via the ImageReader.OnImageAvailableListener interface (included in my library). This is the reason why sometimes images are being captured less frequently (few updates) on a stale Activity. If there are movements, the OS sends more images.

However, included in the library there is the ordinary Screenshot-object. I guess you can execute it "at wish" using a timer. For your purposes though, I think StartShooting-method to start a session of taking continuous screenshots is your best option.

Do I need the advanced version of your library for this purpose (I assume yes) and is it ready/stable enough for the application I intend to build?
Yes, the screenshot-options are included in the advanced version. Many users have donated and so far I have not had any complaints so I guess it works fine.

In any case, since you're a Vitamio5-donator, you could also use the grab screenshot included in Vitamio5.
 

youjunjer

Member
Licensed User
Dear moster67:
Did you finish the work of screenshot? Is this Lib can take screenshot background in setting time interval(such as 60s)?
If yes, where to buy your lib?
 

DonManfred

Expert
Licensed User
If yes, where to buy your lib?

Edit: The free version posted here is OK for screen-recording. There is also a more advanced version of this library which enables screen-recording with audio and capturing screenshots. The advanced version of this library is still a work in progress but users who have bought it are already using it in their apps. At this point of development, the price is EUR 15,00 for the advanced version but it will probably be more when it's ready.
Send me a PM (start a conversation) if you are interested.

Some basic stuff to remember:
1) you need at least Lollipop to get this to work. The library uses MediaProjection which was introduced with SDK 21.
2) You cannot use it for a spy-app. When users run your app and the code in your app which triggers the screen-capturing (recording or screenshots), users have to give permission. Of course, users can tell Android System not to ask for permission anymore and then no more permission will be asked.
3) some apps, such as Telegram, can block MediaProjection and thus capturing/recording of the screen is not possible.


Please remember that creating libraries and maintaining them takes time and so does supporting them. Please consider a donation if you use my free libraries as this will surely help keeping me motivated. Thank you!
 

moster67

Expert
Licensed User
Is this Lib can take screenshot background in setting time interval(such as 60s)
Yes, using the ScreenShotterContinuous object you can. A b4a-sample is included with the paid version.
I have replied to your PM.
 

peacemaker

Expert
Licensed User
Can paid version work from a service ? The free version, seems, does not work.
 

peacemaker

Expert
Licensed User
Yes, ".GetPermission" must be from Activity anyway. But the recorder can work inside a service.
 

mtd13755

New Member
hi
I start recording in activity
but i want to stop recording in service
pls help me by code
 
Last edited:
Top