Android Question Customise the java mediarecorder object in Camera2

CyberDroidWare

Member
Licensed User
Hi all,

With regards to this project, Camera2 Library Example, how do you add inline java code to a B4A application to further customise the mediarecorder.

For example, I need to run this Java (and know what data type and value the constant MediaRecorder.OutputFormat.MPEG_2_TS)

How exactly do you parse this method, get the value for MPEG_2_TS and run the following:

mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_2_TS);

I have tried the usual method and constantly get this:
java.lang.reflect.InvocationTargetException
B4X:
Dim oOF as Int = 8
MediaRecorder.RunMethod("setOutputFormat", Array(oOF)) 'set to TS

I have read this, and I think it may be that the library runs code wrapped in a different order than I can control.

setOutputFormat
Added in API level 1
public void setOutputFormat (int output_format)
Sets the format of the output file produced during recording. Call this after setAudioSource()/setVideoSource() but before prepare().

It is recommended to always use 3GP format when using the H.263 video encoder and AMR audio encoder. Using an MPEG-4 container format may confuse some desktop players.


MPEG_2_TS
Added in API level 26
public static final int MPEG_2_TS
H.264/AAC data encapsulated in MPEG2/TS

Constant Value: 8 (0x00000008)

Parameters
output_formatint: the output format to use. The output format needs to be specified before setting recording-parameters or encoders.
Throws
IllegalStateExceptionif it is called after prepare() or before setAudioSource()/setVideoSource().


Oh, and I am targeting an API > 26
Thanks
S
 
Last edited:
Top