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,941
  • B4XPagesScreenRecorder.zip
    12.5 KB · Views: 1,218
Last edited:

DonManfred

Expert
Licensed User
Longtime User
and I got this error
What is the path to Android.jar you are using? It should point to [...]\Platform-30\Android.jar

Follow the installation instructions carefully:

 

moster67

Expert
Licensed User
Longtime User
why this error?
Please post the complete error output from the logs. You may need to need to disable filter logs in the IDE to do so.
Which android version are you using?
 

mehdipass

Active Member
this error:
android.media.MediaCodec$CodecException: Error 0xfffffc0e
    at android.media.MediaCodec.native_configure(Native Method)
    at android.media.MediaCodec.configure(MediaCodec.java:2023)
    at android.media.MediaCodec.configure(MediaCodec.java:1951)
    at net.yrom.screenrecorder.ScreenRecorder.prepareEncoder(ScreenRecorder.java:175)
    at net.yrom.screenrecorder.ScreenRecorder.run(ScreenRecorder.java:81)


All log:


Capture.PNG


Huawei P30 Lite MAR-LX1A - Android 10
 

moster67

Expert
Licensed User
Longtime User
By googling, it seems like the error is related to Width and Height values on certain devices when the configuration takes place.
Try to change Width and Height in the StartRecording method.

Others say it might be related to the MediaPlayer (in the sample project I used VideoView) not being released when being used together with MediaProjection. Try to set VideoView = null once you have finished playing the recorded video and then reinitialize it before showing another video or perhaps use another video player.

Sorry that I cannot be of any further help.
 

mehdipass

Active Member
By googling, it seems like the error is related to Width and Height values on certain devices when the configuration takes place.
Try to change Width and Height in the StartRecording method.

Others say it might be related to the MediaPlayer (in the sample project I used VideoView) not being released when being used together with MediaProjection. Try to set VideoView = null once you have finished playing the recorded video and then reinitialize it before showing another video or perhaps use another video player.

Sorry that I cannot be of any further help.
Okay, thanks, I'll give it a try.
 

stari

Active Member
Licensed User
Longtime User
Error
I get this by compiling:
B4A Version: 13.00
Parsing code. (0.05s)
Java Version: 19
Building folders structure. (0.02s)
Running custom action. Error
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Friday, October 25, 2024 7:33:12 AM
Source : D:\70 let\Shared Files\
Dest : D:\70 let\B4A\Files\
Files : *.*

Options : *.* /DCOPY:DA /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
2024/10/25 07:33:12 ERROR 2 (0x00000002) Accessing Source Directory D:\70 let\Shared Files\
The system cannot find the file specified.

What is wrong ?
 
Top