Search in sources :

Example 81 with MediaRecorder

use of android.media.MediaRecorder in project storymaker by StoryMaker.

the class ExtAudioRecorder method reset.

/**
	 * 
	 * 
	 * Resets the recorder to the INITIALIZING state, as if it was just created.
	 * In case the class was in RECORDING state, the recording is stopped.
	 * In case of exceptions the class is set to the ERROR state.
	 * 
	 */
public void reset() {
    try {
        if (state != State.ERROR) {
            release();
            // Reset file path
            filePath = null;
            // Reset amplitude
            cAmplitude = 0;
            if (rUncompressed) {
                audioRecorder = new AudioRecord(aSource, sRate, nChannels + 1, aFormat, bufferSize);
            } else {
                mediaRecorder = new MediaRecorder();
                mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
                mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
            }
            state = State.INITIALIZING;
        }
    } catch (Exception e) {
        Timber.e(e.getMessage());
        state = State.ERROR;
    }
}
Also used : AudioRecord(android.media.AudioRecord) MediaRecorder(android.media.MediaRecorder) IOException(java.io.IOException)

Example 82 with MediaRecorder

use of android.media.MediaRecorder in project android_frameworks_base by DirtyUnicorns.

the class CodecTest method mediaRecorderRecord.

public static boolean mediaRecorderRecord(String filePath) {
    Log.v(TAG, "SoundRecording - " + filePath);
    //This test is only for the short media file
    int duration = 0;
    try {
        MediaRecorder mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        mRecorder.setOutputFile(filePath);
        mRecorder.prepare();
        mRecorder.start();
        Thread.sleep(500);
        mRecorder.stop();
        Log.v(TAG, "sound recorded");
        mRecorder.release();
    } catch (Exception e) {
        Log.v(TAG, e.toString());
    }
    //Verify the recorded file
    MediaPlayer mp = new MediaPlayer();
    try {
        mp.setDataSource(filePath);
        mp.prepare();
        duration = mp.getDuration();
        Log.v(TAG, "Duration " + duration);
        mp.release();
    } catch (Exception e) {
    }
    //Check the record media file length is greate than zero
    if (duration > 0)
        return true;
    else
        return false;
}
Also used : MediaRecorder(android.media.MediaRecorder) IOException(java.io.IOException) MediaPlayer(android.media.MediaPlayer)

Example 83 with MediaRecorder

use of android.media.MediaRecorder in project android_frameworks_base by DirtyUnicorns.

the class MediaPlayerPerformance method stressAudioRecord.

public void stressAudioRecord(String filePath) {
    // This test is only for the short media file
    for (int i = 0; i < NUM_PLAYBACk_IN_EACH_LOOP; i++) {
        MediaRecorder mRecorder = new MediaRecorder();
        try {
            mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
            mRecorder.setOutputFile(filePath);
            mRecorder.prepare();
            mRecorder.start();
            Thread.sleep(MEDIA_STRESS_WAIT_TIME);
            mRecorder.stop();
            mRecorder.release();
        } catch (Exception e) {
            Log.v(TAG, e.toString());
            mRecorder.release();
        }
    }
}
Also used : MediaRecorder(android.media.MediaRecorder) IOException(java.io.IOException)

Example 84 with MediaRecorder

use of android.media.MediaRecorder in project android_frameworks_base by DirtyUnicorns.

the class Camera2RecordingTest method doBasicRecording.

private void doBasicRecording(boolean useVideoStab) throws Exception {
    for (int i = 0; i < mCameraIds.length; i++) {
        try {
            Log.i(TAG, "Testing basic recording for camera " + mCameraIds[i]);
            // Re-use the MediaRecorder object for the same camera device.
            mMediaRecorder = new MediaRecorder();
            openDevice(mCameraIds[i]);
            if (!mStaticInfo.isColorOutputSupported()) {
                Log.i(TAG, "Camera " + mCameraIds[i] + " does not support color outputs, skipping");
                continue;
            }
            if (!mStaticInfo.isVideoStabilizationSupported() && useVideoStab) {
                Log.i(TAG, "Camera " + mCameraIds[i] + " does not support video stabilization, skipping the stabilization" + " test");
                continue;
            }
            initSupportedVideoSize(mCameraIds[i]);
            // Test iteration starts...
            for (int iteration = 0; iteration < getIterationCount(); ++iteration) {
                Log.v(TAG, String.format("Recording video: %d/%d", iteration + 1, getIterationCount()));
                basicRecordingTestByCamera(mCamcorderProfileList, useVideoStab);
                getResultPrinter().printStatus(getIterationCount(), iteration + 1, mCameraIds[i]);
                Thread.sleep(getTestWaitIntervalMs());
            }
        } finally {
            closeDevice();
            releaseRecorder();
        }
    }
}
Also used : MediaRecorder(android.media.MediaRecorder)

Example 85 with MediaRecorder

use of android.media.MediaRecorder in project android_frameworks_base by DirtyUnicorns.

the class Camera2RecordingTest method videoSnapshotHelper.

/**
     * Simple wrapper to wrap normal/burst video snapshot tests
     */
private void videoSnapshotHelper(boolean burstTest) throws Exception {
    for (String id : mCameraIds) {
        try {
            Log.i(TAG, "Testing video snapshot for camera " + id);
            // Re-use the MediaRecorder object for the same camera device.
            mMediaRecorder = new MediaRecorder();
            openDevice(id);
            if (!mStaticInfo.isColorOutputSupported()) {
                Log.i(TAG, "Camera " + id + " does not support color outputs, skipping");
                continue;
            }
            initSupportedVideoSize(id);
            // Test iteration starts...
            for (int iteration = 0; iteration < getIterationCount(); ++iteration) {
                Log.v(TAG, String.format("Video snapshot: %d/%d", iteration + 1, getIterationCount()));
                videoSnapshotTestByCamera(burstTest);
                getResultPrinter().printStatus(getIterationCount(), iteration + 1, id);
                Thread.sleep(getTestWaitIntervalMs());
            }
        } finally {
            closeDevice();
            releaseRecorder();
        }
    }
}
Also used : MediaRecorder(android.media.MediaRecorder)

Aggregations

MediaRecorder (android.media.MediaRecorder)107 IOException (java.io.IOException)58 MediaPlayer (android.media.MediaPlayer)18 Paint (android.graphics.Paint)15 CamcorderProfile (android.media.CamcorderProfile)15 SurfaceHolder (android.view.SurfaceHolder)12 Surface (android.view.Surface)11 File (java.io.File)9 Camera (android.hardware.Camera)8 MutableFrameFormat (android.filterfw.core.MutableFrameFormat)6 Point (android.filterfw.geometry.Point)6 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)6 LargeTest (android.test.suitebuilder.annotation.LargeTest)6 Size (android.util.Size)6 Canvas (android.graphics.Canvas)5 Range (android.util.Range)5 SimpleCaptureCallback (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)5 Activity (android.app.Activity)4 Point (android.graphics.Point)4 Uri (android.net.Uri)3