10. Media
ARGear provides image or video capture through ARGMedia. Users can take a photo or shoot a video in the available ratios, 16:9, 4:3, 1:1.

10.1 Take a Photo

Using the takePicture function in ARGMedia, users can take a photo.
The function must be called in gl thread environment.
Sample code is written below.
Java
Kotlin
1
ARGMedia argmedia = new ARGMedia(argsession);
2
3
GLView.GLViewListener glViewListener = new GLView.GLViewListener() {
4
5
@Override
6
public void onDrawFrame(GL10 gl, int width, int height) {
7
8
ARGFrame frame = mARGSession.drawFrame(gl, width, height);
9
if (argmedia != null) {
10
if (mIsShooting) {
11
String path = Environment.getExternalStorageDirectory() + "/" + System.currentTimeMillis() + ".jpg";
12
argmedia.takePicture(frame.getTextureId(), path, ARGMedia.Ratio.RATIO_4_3);
13
}
14
}
15
16
}
17
};
Copied!
1
var argmedia = ARGMedia(argsession)
2
3
override fun onDrawFrame(gl: GL10?, width: Int?, height: Int?) {
4
5
val localWidth = width ?: 0
6
val localHeight = height ?: 0
7
val frame = argsession.drawFrame(gl, localWidth, localHeight)
8
frame?.let {
9
if (isShooting) {
10
val path = mediaPath + "/" + System.currentTimeMillis() + ".jpg"
11
argmedia.takePicture(textureId, path, ARGMedia.Ratio.RATIO_4_3)
12
}
13
}
14
15
}
Copied!

10.2 Record a Video

ARGMedia provides several functions to record a video. Through the functions you can control bitrate, silent mode, and video frame size ratio.
Sample code to record a video is written below.
Java
Kotlin
1
ARGMedia argmedia = new ARGMedia(argsession);
2
3
private void startRecording() {
4
int bitrate = 10 * 1000 * 1000; // 10M
5
int [] previewSize = mCamera.getPreviewSize();
6
mVideoFilePath = Environment.getExternalStorageDirectory() + "/" + System.currentTimeMillis() + ".mp4";
7
8
// Initiate Recorder
9
argmedia.initRecorder(mVideoFilePath,
10
previewSize[0], previewSize[1], bitrate,
11
false, false, false, ARGMedia.Ratio.RATIO_4_3);
12
// Start Recording
13
argmedia.startRecording();
14
}
15
16
private void stopRecording() {
17
// Stop Recording
18
argmedia.stopRecording();
19
}
20
21
GLView.GLViewListener glViewListener = new GLView.GLViewListener() {
22
23
@Override
24
public void onDrawFrame(GL10 gl, int width, int height) {
25
26
ARGFrame frame = mARGSession.drawFrame(gl, width, height);
27
if (argmedia != null && argmedia.isRecording()) {
28
// Update Recording Frame
29
argmedia.updateFrame(frame.getTextureId());
30
}
31
32
}
33
};
Copied!
1
var argmedia = new ARGMedia(argsession);
2
3
private fun startRecording() {
4
val bitrate = 10 * 1000 * 1000 // 10M
5
val previewSize: IntArray? = camera.previewSize
6
val videoFilePath = mediaPath + "/" + System.currentTimeMillis() + ".mp4"
7
8
argMedia.initRecorder(
9
videoFilePath, previewSize[0], previewSize[1], bitrate,
10
false, false, false, ARGMedia.Ratio.RATIO_4_3
11
)
12
13
argMedia.startRecording()
14
}
15
16
private fun stopRecording() {
17
argmedia.stopRecording()
18
}
19
20
override fun onDrawFrame(gl: GL10?, width: Int?, height: Int?) {
21
22
val localWidth = width ?: 0
23
val localHeight = height ?: 0
24
val frame = argsession.drawFrame(gl, localWidth, localHeight)
25
frame?.let {
26
if (argmedia.isRecording) argmedia.updateFrame(it.textureId)
27
}
28
}
Copied!
Last modified 1yr ago