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.
ARGMedia argmedia = new ARGMedia(argsession);
GLView.GLViewListener glViewListener = new GLView.GLViewListener() {
@Override
public void onDrawFrame(GL10 gl, int width, int height) {
ARGFrame frame = mARGSession.drawFrame(gl, width, height);
if (argmedia != null) {
if (mIsShooting) {
String path = Environment.getExternalStorageDirectory() + "/" + System.currentTimeMillis() + ".jpg";
argmedia.takePicture(frame.getTextureId(), path, ARGMedia.Ratio.RATIO_4_3);
}
}
}
};
var argmedia = ARGMedia(argsession)
override fun onDrawFrame(gl: GL10?, width: Int?, height: Int?) {
val localWidth = width ?: 0
val localHeight = height ?: 0
val frame = argsession.drawFrame(gl, localWidth, localHeight)
frame?.let {
if (isShooting) {
val path = mediaPath + "/" + System.currentTimeMillis() + ".jpg"
argmedia.takePicture(textureId, path, ARGMedia.Ratio.RATIO_4_3)
}
}
}
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.
ARGMedia argmedia = new ARGMedia(argsession);
private void startRecording() {
int bitrate = 10 * 1000 * 1000; // 10M
int [] previewSize = mCamera.getPreviewSize();
mVideoFilePath = Environment.getExternalStorageDirectory() + "/" + System.currentTimeMillis() + ".mp4";
// Initiate Recorder
argmedia.initRecorder(mVideoFilePath,
previewSize[0], previewSize[1], bitrate,
false, false, false, ARGMedia.Ratio.RATIO_4_3);
// Start Recording
argmedia.startRecording();
}
private void stopRecording() {
// Stop Recording
argmedia.stopRecording();
}
GLView.GLViewListener glViewListener = new GLView.GLViewListener() {
@Override
public void onDrawFrame(GL10 gl, int width, int height) {
ARGFrame frame = mARGSession.drawFrame(gl, width, height);
if (argmedia != null && argmedia.isRecording()) {
// Update Recording Frame
argmedia.updateFrame(frame.getTextureId());
}
}
};
var argmedia = new ARGMedia(argsession);
private fun startRecording() {
val bitrate = 10 * 1000 * 1000 // 10M
val previewSize: IntArray? = camera.previewSize
val videoFilePath = mediaPath + "/" + System.currentTimeMillis() + ".mp4"
argMedia.initRecorder(
videoFilePath, previewSize[0], previewSize[1], bitrate,
false, false, false, ARGMedia.Ratio.RATIO_4_3
)
argMedia.startRecording()
}
private fun stopRecording() {
argmedia.stopRecording()
}
override fun onDrawFrame(gl: GL10?, width: Int?, height: Int?) {
val localWidth = width ?: 0
val localHeight = height ?: 0
val frame = argsession.drawFrame(gl, localWidth, localHeight)
frame?.let {
if (argmedia.isRecording) argmedia.updateFrame(it.textureId)
}
}