Search in sources :

Example 11 with MediaRecorder

use of android.media.MediaRecorder in project Lazy by l123456789jy.

the class RecorderControl method startRecording.

/*
	 * 开始录音
	 */
public void startRecording() {
    // 实例化MediaRecorder
    if (mRecorder == null) {
        mRecorder = new MediaRecorder();
    }
    // 设置音频源为MIC
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    // 设置输出文件的格式
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
    //		mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    // 设置输出文件的名称
    mRecorder.setOutputFile(mFileName);
    //设置音频的编码格式
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    //		mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
    //设置采样率
    mRecorder.setAudioSamplingRate(SAMPLE_RATE_IN_HZ);
    try {
        //得到设置的音频来源,编码器,文件格式等等内容,在start()之前调用
        mRecorder.prepare();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        //开始录音
        mRecorder.start();
    } catch (Exception e) {
        mRecorder = null;
        mRecorder = new MediaRecorder();
    }
}
Also used : MediaRecorder(android.media.MediaRecorder) IOException(java.io.IOException) IOException(java.io.IOException)

Example 12 with MediaRecorder

use of android.media.MediaRecorder in project platform_frameworks_base by android.

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 13 with MediaRecorder

use of android.media.MediaRecorder in project platform_frameworks_base by android.

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)

Example 14 with MediaRecorder

use of android.media.MediaRecorder in project platform_frameworks_base by android.

the class Camera2RecordingTest method constrainedHighSpeedRecording.

private void constrainedHighSpeedRecording() throws Exception {
    for (String id : mCameraIds) {
        try {
            Log.i(TAG, "Testing constrained high speed recording for camera " + id);
            // Re-use the MediaRecorder object for the same camera device.
            mMediaRecorder = new MediaRecorder();
            openDevice(id);
            if (!mStaticInfo.isConstrainedHighSpeedVideoSupported()) {
                Log.i(TAG, "Camera " + id + " doesn't support high speed recording, skipping.");
                continue;
            }
            // Test iteration starts...
            for (int iteration = 0; iteration < getIterationCount(); ++iteration) {
                Log.v(TAG, String.format("Constrained high speed recording: %d/%d", iteration + 1, getIterationCount()));
                StreamConfigurationMap config = mStaticInfo.getValueFromKeyNonNull(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
                Size[] highSpeedVideoSizes = config.getHighSpeedVideoSizes();
                for (Size size : highSpeedVideoSizes) {
                    List<Range<Integer>> fixedFpsRanges = getHighSpeedFixedFpsRangeForSize(config, size);
                    mCollector.expectTrue("Unable to find the fixed frame rate fps range for " + "size " + size, fixedFpsRanges.size() > 0);
                    // Test recording for each FPS range
                    for (Range<Integer> fpsRange : fixedFpsRanges) {
                        int captureRate = fpsRange.getLower();
                        final int VIDEO_FRAME_RATE = 30;
                        // Skip the test if the highest recording FPS supported by CamcorderProfile
                        if (fpsRange.getUpper() > getFpsFromHighSpeedProfileForSize(size)) {
                            Log.w(TAG, "high speed recording " + size + "@" + captureRate + "fps" + " is not supported by CamcorderProfile");
                            continue;
                        }
                        mOutMediaFileName = VIDEO_FILE_PATH + "/test_cslowMo_video_" + captureRate + "fps_" + id + "_" + size.toString() + ".mp4";
                        prepareRecording(size, VIDEO_FRAME_RATE, captureRate);
                        // prepare preview surface by using video size.
                        updatePreviewSurfaceWithVideo(size, captureRate);
                        // Start recording
                        SimpleCaptureCallback resultListener = new SimpleCaptureCallback();
                        startSlowMotionRecording(/*useMediaRecorder*/
                        true, VIDEO_FRAME_RATE, captureRate, fpsRange, resultListener, /*useHighSpeedSession*/
                        true);
                        // Record certain duration.
                        SystemClock.sleep(RECORDING_DURATION_MS);
                        // Stop recording and preview
                        stopRecording(/*useMediaRecorder*/
                        true);
                        // Convert number of frames camera produced into the duration in unit of ms.
                        int durationMs = (int) (resultListener.getTotalNumFrames() * 1000.0f / VIDEO_FRAME_RATE);
                        // Validation.
                        validateRecording(size, durationMs);
                    }
                    getResultPrinter().printStatus(getIterationCount(), iteration + 1, id);
                    Thread.sleep(getTestWaitIntervalMs());
                }
            }
        } finally {
            closeDevice();
            releaseRecorder();
        }
    }
}
Also used : Size(android.util.Size) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap) MediaRecorder(android.media.MediaRecorder) Range(android.util.Range) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)

Example 15 with MediaRecorder

use of android.media.MediaRecorder in project platform_frameworks_base by android.

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)

Aggregations

MediaRecorder (android.media.MediaRecorder)106 IOException (java.io.IOException)57 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 Camera (android.hardware.Camera)8 File (java.io.File)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