Skip to content

Instantly share code, notes, and snippets.

@chikadance
Created May 5, 2016 07:28
Show Gist options
  • Save chikadance/618198030c2ad459ad85f8961d59b6b1 to your computer and use it in GitHub Desktop.
Save chikadance/618198030c2ad459ad85f8961d59b6b1 to your computer and use it in GitHub Desktop.
TestMr
package ro.rotry;
import android.media.MediaRecorder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.io.IOException;
public class TestMr extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_mr);
MediaRecorder mr = new MediaRecorder();
mr.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mr.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mr.setVideoSize(1920, 1080);
mr.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mr.setVideoEncodingBitRate(12 * 1000 * 1000);
mr.setVideoFrameRate(60);
mr.setOutputFile(getFilesDir() + "/try.mp4");
try {
mr.prepare();
} catch (IOException e) {
throw new RuntimeException(e);
}
mr.start();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
mr.stop();
mr.reset(); // You can reuse the object by going back to setAudioSource() step
mr.release(); // Now the object cannot be reused
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment