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);
            }
        }

    }
};

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());
        }

    }
};

Last updated