use of android.media.MediaRecorder in project SmartCampus by Vegen.
the class EaseVoiceRecorder method startRecording.
/**
* start recording to the file
*/
public String startRecording(Context appContext) {
file = null;
try {
// from setOutputFile when try to reuse
if (recorder != null) {
recorder.release();
recorder = null;
}
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
// MONO
recorder.setAudioChannels(1);
// 8000Hz
recorder.setAudioSamplingRate(8000);
// seems if change this to
recorder.setAudioEncodingBitRate(64);
// 128, still got same file
// size.
// one easy way is to use temp file
// file = File.createTempFile(PREFIX + userId, EXTENSION,
// User.getVoicePath());
voiceFileName = getVoiceFileName(EMClient.getInstance().getCurrentUser());
voiceFilePath = PathUtil.getInstance().getVoicePath() + "/" + voiceFileName;
file = new File(voiceFilePath);
recorder.setOutputFile(file.getAbsolutePath());
recorder.prepare();
isRecording = true;
recorder.start();
} catch (IOException e) {
EMLog.e("voice", "prepare() failed");
}
new Thread(new Runnable() {
@Override
public void run() {
try {
while (isRecording) {
android.os.Message msg = new android.os.Message();
msg.what = recorder.getMaxAmplitude() * 13 / 0x7FFF;
handler.sendMessage(msg);
SystemClock.sleep(100);
}
} catch (Exception e) {
// from the crash report website, found one NPE crash from
// one android 4.0.4 htc phone
// maybe handler is null for some reason
EMLog.e("voice", e.toString());
}
}
}).start();
startTime = new Date().getTime();
EMLog.d("voice", "start voice recording to file:" + file.getAbsolutePath());
return file == null ? null : file.getAbsolutePath();
}
use of android.media.MediaRecorder in project libstreaming by fyhertz.
the class VideoStream method encodeWithMediaRecorder.
/**
* Video encoding is done by a MediaRecorder.
*/
protected void encodeWithMediaRecorder() throws IOException, ConfNotSupportedException {
Log.d(TAG, "Video encoded using the MediaRecorder API");
// We need a local socket to forward data output by the camera to the packetizer
createSockets();
// Reopens the camera if needed
destroyCamera();
createCamera();
// The camera must be unlocked before the MediaRecorder can use it
unlockCamera();
try {
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mMediaRecorder.setVideoEncoder(mVideoEncoder);
mMediaRecorder.setPreviewDisplay(mSurfaceView.getHolder().getSurface());
mMediaRecorder.setVideoSize(mRequestedQuality.resX, mRequestedQuality.resY);
mMediaRecorder.setVideoFrameRate(mRequestedQuality.framerate);
// The bandwidth actually consumed is often above what was requested
mMediaRecorder.setVideoEncodingBitRate((int) (mRequestedQuality.bitrate * 0.8));
// We write the output of the camera in a local socket instead of a file !
// This one little trick makes streaming feasible quiet simply: data from the camera
// can then be manipulated at the other end of the socket
FileDescriptor fd = null;
if (sPipeApi == PIPE_API_PFD) {
fd = mParcelWrite.getFileDescriptor();
} else {
fd = mSender.getFileDescriptor();
}
mMediaRecorder.setOutputFile(fd);
mMediaRecorder.prepare();
mMediaRecorder.start();
} catch (Exception e) {
throw new ConfNotSupportedException(e.getMessage());
}
InputStream is = null;
if (sPipeApi == PIPE_API_PFD) {
is = new ParcelFileDescriptor.AutoCloseInputStream(mParcelRead);
} else {
is = mReceiver.getInputStream();
}
// This will skip the MPEG4 header if this step fails we can't stream anything :(
try {
byte[] buffer = new byte[4];
// Skip all atoms preceding mdat atom
while (!Thread.interrupted()) {
while (is.read() != 'm') ;
is.read(buffer, 0, 3);
if (buffer[0] == 'd' && buffer[1] == 'a' && buffer[2] == 't')
break;
}
} catch (IOException e) {
Log.e(TAG, "Couldn't skip mp4 header :/");
stop();
throw e;
}
// The packetizer encapsulates the bit stream in an RTP stream and send it over the network
mPacketizer.setInputStream(is);
mPacketizer.start();
mStreaming = true;
}
use of android.media.MediaRecorder in project KJFrameForAndroid by kymjs.
the class RecordButtonUtil method initRecorder.
// 初始化 录音器
private void initRecorder() {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile(mAudioPath);
mIsRecording = true;
}
use of android.media.MediaRecorder in project coursera-android by aporter.
the class AudioRecordingActivity method startRecording.
// Start recording with MediaRecorder
private void startRecording() {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(TAG, "Couldn't prepare and start MediaRecorder");
}
mRecorder.start();
}
use of android.media.MediaRecorder in project CameraKit-Android by flurgle.
the class Camera1 method initMediaRecorder.
private void initMediaRecorder() {
mMediaRecorder = new MediaRecorder();
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_480P));
mVideoFile = new File(mPreview.getView().getContext().getExternalFilesDir(null), "video.mp4");
mMediaRecorder.setOutputFile(mVideoFile.getAbsolutePath());
mMediaRecorder.setMaxDuration(20000);
mMediaRecorder.setMaxFileSize(5000000);
mMediaRecorder.setOrientationHint(mCameraInfo.orientation);
}
Aggregations