Search in sources :

Example 16 with MediaRecorder

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

the class Camera2SwitchPreviewTest method recordingPreviewPreparer.

private void recordingPreviewPreparer(String id) throws Exception {
    // Re-use the MediaRecorder object for the same camera device.
    mMediaRecorder = new MediaRecorder();
    initSupportedVideoSize(id);
    // preview Setup:
    basicRecordingPreviewTestByCamera(mCamcorderProfileList);
    Thread.sleep(getTestWaitIntervalMs());
}
Also used : MediaRecorder(android.media.MediaRecorder)

Example 17 with MediaRecorder

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

the class MediaRecorderStressTest method testStressTimeLapse.

// Test case for stressing time lapse
@LargeTest
public void testStressTimeLapse() throws Exception {
    SurfaceHolder mSurfaceHolder;
    mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
    int recordDuration = MediaRecorderStressTestRunner.mTimeLapseDuration;
    boolean removeVideo = MediaRecorderStressTestRunner.mRemoveVideo;
    double captureRate = MediaRecorderStressTestRunner.mCaptureRate;
    Log.v(TAG, "Start camera time lapse stress:");
    mOutput.write("Total number of loops: " + NUMBER_OF_TIME_LAPSE_LOOPS + "\n");
    try {
        for (int i = 0, n = Camera.getNumberOfCameras(); i < n; i++) {
            mOutput.write("No of loop: camera " + i);
            for (int j = 0; j < NUMBER_OF_TIME_LAPSE_LOOPS; j++) {
                String fileName = String.format("%s/temp%d_%d%s", Environment.getExternalStorageDirectory(), i, j, OUTPUT_FILE_EXT);
                Log.v(TAG, fileName);
                runOnLooper(new Runnable() {

                    @Override
                    public void run() {
                        mRecorder = new MediaRecorder();
                    }
                });
                // Set callback
                mRecorder.setOnErrorListener(mRecorderErrorCallback);
                // Set video source
                mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
                // Set camcorder profile for time lapse
                CamcorderProfile profile = CamcorderProfile.get(j, CamcorderProfile.QUALITY_TIME_LAPSE_HIGH);
                mRecorder.setProfile(profile);
                // Set the timelapse setting; 0.1 = 10 sec timelapse, 0.5 = 2 sec timelapse, etc
                // http://developer.android.com/guide/topics/media/camera.html#time-lapse-video
                mRecorder.setCaptureRate(captureRate);
                // Set output file
                mRecorder.setOutputFile(fileName);
                // Set the preview display
                Log.v(TAG, "mediaRecorder setPreviewDisplay");
                mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
                mRecorder.prepare();
                mRecorder.start();
                Thread.sleep(recordDuration);
                Log.v(TAG, "Before stop");
                mRecorder.stop();
                mRecorder.release();
                // Start the playback
                MediaPlayer mp = new MediaPlayer();
                mp.setDataSource(fileName);
                mp.setDisplay(mSurfaceHolder);
                mp.prepare();
                mp.start();
                Thread.sleep(TIME_LAPSE_PLAYBACK_WAIT_TIME);
                mp.release();
                validateRecordedVideo(fileName);
                if (removeVideo) {
                    removeRecordedVideo(fileName);
                }
                if (j == 0) {
                    mOutput.write(j + 1);
                } else {
                    mOutput.write(String.format(", %d", (j + 1)));
                }
            }
        }
    } catch (IllegalStateException e) {
        Log.e(TAG, e.toString());
        fail("Camera time lapse stress test IllegalStateException");
    } catch (IOException e) {
        Log.e(TAG, e.toString());
        fail("Camera time lapse stress test IOException");
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        fail("Camera time lapse stress test Exception");
    }
}
Also used : CamcorderProfile(android.media.CamcorderProfile) IOException(java.io.IOException) IOException(java.io.IOException) SurfaceHolder(android.view.SurfaceHolder) MediaRecorder(android.media.MediaRecorder) MediaPlayer(android.media.MediaPlayer) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 18 with MediaRecorder

use of android.media.MediaRecorder in project AndroidSDK-RecipeBook by gabu.

the class Recipe062 method onStartButton.

// Startボタンが押されたら呼び出される
public void onStartButton(View view) {
    if (isRecording)
        return;
    mTextView.setText("Recording...");
    // SDカードのディレクトリ
    File dir = Environment.getExternalStorageDirectory();
    // アプリ名で
    File appDir = new File(dir, "Recipe062");
    // ディレクトリを作る
    if (!appDir.exists())
        appDir.mkdir();
    // ファイル名
    String name = System.currentTimeMillis() + ".3gp";
    // 出力ファイルのパス
    String path = new File(appDir, name).getAbsolutePath();
    mRecorder = new MediaRecorder();
    // 入力ソースにマイクを指定
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    // 出力フォーマットに3gpを指定
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    // 音声エンコーダにAMRを指定
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    // 出力ファイルのパスを指定
    mRecorder.setOutputFile(path);
    try {
        // 準備して
        mRecorder.prepare();
        // 録音スタート!
        mRecorder.start();
        isRecording = true;
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : MediaRecorder(android.media.MediaRecorder) IOException(java.io.IOException) File(java.io.File)

Example 19 with MediaRecorder

use of android.media.MediaRecorder in project AndroidSDK-RecipeBook by gabu.

the class Recipe066 method onStartButton.

public void onStartButton(View view) {
    // MediaRecorderを作って
    mRecorder = new MediaRecorder();
    // ビデオ入力にカメラをセット
    mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    // オーディオ入力にマイクをセット
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    // 出力フォーマットに3gpをセット
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    // 出力ファイルパスを作って
    String path = createFilePath();
    // セット
    mRecorder.setOutputFile(path);
    // フレームレートをセット
    mRecorder.setVideoFrameRate(15);
    // 撮影サイズを指定
    // 端末のカメラに依存するので気をつけてください。
    mRecorder.setVideoSize(800, 480);
    // ビデオエンコーダーにMPEG_4_SPをセット
    mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
    // オーディオエンコーダーにAMR_NBをセット
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    // プレビュー表示にSurfaceをセット
    mRecorder.setPreviewDisplay(mCameraView.getHolder().getSurface());
    try {
        // 準備して
        mRecorder.prepare();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // 録画スタート!
    mRecorder.start();
}
Also used : MediaRecorder(android.media.MediaRecorder) IOException(java.io.IOException)

Example 20 with MediaRecorder

use of android.media.MediaRecorder in project libstreaming by fyhertz.

the class AACStream method testADTS.

/** 
	 * Records a short sample of AAC ADTS from the microphone to find out what the sampling rate really is
	 * On some phone indeed, no error will be reported if the sampling rate used differs from the 
	 * one selected with setAudioSamplingRate 
	 * @throws IOException 
	 * @throws IllegalStateException
	 */
@SuppressLint("InlinedApi")
private void testADTS() throws IllegalStateException, IOException {
    setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    try {
        Field name = MediaRecorder.OutputFormat.class.getField("AAC_ADTS");
        setOutputFormat(name.getInt(null));
    } catch (Exception ignore) {
        setOutputFormat(6);
    }
    String key = PREF_PREFIX + "aac-" + mQuality.samplingRate;
    if (mSettings != null && mSettings.contains(key)) {
        String[] s = mSettings.getString(key, "").split(",");
        mQuality.samplingRate = Integer.valueOf(s[0]);
        mConfig = Integer.valueOf(s[1]);
        mChannel = Integer.valueOf(s[2]);
        return;
    }
    final String TESTFILE = Environment.getExternalStorageDirectory().getPath() + "/spydroid-test.adts";
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        throw new IllegalStateException("No external storage or external storage not ready !");
    }
    // The structure of an ADTS packet is described here: http://wiki.multimedia.cx/index.php?title=ADTS
    // ADTS header is 7 or 9 bytes long
    byte[] buffer = new byte[9];
    mMediaRecorder = new MediaRecorder();
    mMediaRecorder.setAudioSource(mAudioSource);
    mMediaRecorder.setOutputFormat(mOutputFormat);
    mMediaRecorder.setAudioEncoder(mAudioEncoder);
    mMediaRecorder.setAudioChannels(1);
    mMediaRecorder.setAudioSamplingRate(mQuality.samplingRate);
    mMediaRecorder.setAudioEncodingBitRate(mQuality.bitRate);
    mMediaRecorder.setOutputFile(TESTFILE);
    mMediaRecorder.setMaxDuration(1000);
    mMediaRecorder.prepare();
    mMediaRecorder.start();
    // TODO: use the MediaRecorder.OnInfoListener
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
    }
    mMediaRecorder.stop();
    mMediaRecorder.release();
    mMediaRecorder = null;
    File file = new File(TESTFILE);
    RandomAccessFile raf = new RandomAccessFile(file, "r");
    // ADTS packets start with a sync word: 12bits set to 1
    while (true) {
        if ((raf.readByte() & 0xFF) == 0xFF) {
            buffer[0] = raf.readByte();
            if ((buffer[0] & 0xF0) == 0xF0)
                break;
        }
    }
    raf.read(buffer, 1, 5);
    mSamplingRateIndex = (buffer[1] & 0x3C) >> 2;
    mProfile = ((buffer[1] & 0xC0) >> 6) + 1;
    mChannel = (buffer[1] & 0x01) << 2 | (buffer[2] & 0xC0) >> 6;
    mQuality.samplingRate = AUDIO_SAMPLING_RATES[mSamplingRateIndex];
    // 5 bits for the object type / 4 bits for the sampling rate / 4 bits for the channel / padding
    mConfig = (mProfile & 0x1F) << 11 | (mSamplingRateIndex & 0x0F) << 7 | (mChannel & 0x0F) << 3;
    Log.i(TAG, "MPEG VERSION: " + ((buffer[0] & 0x08) >> 3));
    Log.i(TAG, "PROTECTION: " + (buffer[0] & 0x01));
    Log.i(TAG, "PROFILE: " + AUDIO_OBJECT_TYPES[mProfile]);
    Log.i(TAG, "SAMPLING FREQUENCY: " + mQuality.samplingRate);
    Log.i(TAG, "CHANNEL: " + mChannel);
    raf.close();
    if (mSettings != null) {
        Editor editor = mSettings.edit();
        editor.putString(key, mQuality.samplingRate + "," + mConfig + "," + mChannel);
        editor.commit();
    }
    if (!file.delete())
        Log.e(TAG, "Temp file could not be erased");
}
Also used : Field(java.lang.reflect.Field) RandomAccessFile(java.io.RandomAccessFile) MediaRecorder(android.media.MediaRecorder) Editor(android.content.SharedPreferences.Editor) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) IOException(java.io.IOException) SuppressLint(android.annotation.SuppressLint)

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