android


What does Android MediaRecorder.prepare() do?


The official Android documentation for MediaRecorder.prepare() says:
Prepares the recorder to begin capturing and encoding data. This method must be called after setting up the desired audio and video sources, encoders, file format, etc., but before start().
What exactly does it do, and why do we need to call it before we start to capture media data?
this function (prepare()) will be creates a random-access file stream to read from a file with the specified name and optionally write to a file.
This is required for stream processing. The stream process will not be started unless this function is used.
see this doc.
You might want to read the source code here: MediaRecorder.java:833
A glimpse of the code:
/**
* Prepares the recorder to begin capturing and encoding data. This method
* must be called after setting up the desired audio and video sources,
* encoders, file format, etc., but before start().
*
* #throws IllegalStateException if it is called after
* start() or before setOutputFormat().
* #throws IOException if prepare fails otherwise.
*/
public void prepare() throws IllegalStateException, IOException
{
if (mPath != null) {
RandomAccessFile file = new RandomAccessFile(mPath, "rws");
try {
_setOutputFile(file.getFD(), 0, 0);
} finally {
file.close();
}
} else if (mFd != null) {
_setOutputFile(mFd, 0, 0);
} else {
throw new IOException("No valid output file");
}
_prepare();
}
And the native part of the code here: mediarecorder.cpp
status_t MediaRecorder::prepare()
{
ALOGV("prepare");
if (mMediaRecorder == NULL) {
ALOGE("media recorder is not initialized yet");
return INVALID_OPERATION;
}
if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
ALOGE("prepare called in an invalid state: %d", mCurrentState);
return INVALID_OPERATION;
}
if (mIsAudioSourceSet != mIsAudioEncoderSet) {
if (mIsAudioSourceSet) {
ALOGE("audio source is set, but audio encoder is not set");
} else { // must not happen, since setAudioEncoder checks this already
ALOGE("audio encoder is set, but audio source is not set");
}
return INVALID_OPERATION;
}
if (mIsVideoSourceSet != mIsVideoEncoderSet) {
if (mIsVideoSourceSet) {
ALOGE("video source is set, but video encoder is not set");
} else { // must not happen, since setVideoEncoder checks this already
ALOGE("video encoder is set, but video source is not set");
}
return INVALID_OPERATION;
}
status_t ret = mMediaRecorder->prepare();
if (OK != ret) {
ALOGE("prepare failed: %d", ret);
mCurrentState = MEDIA_RECORDER_ERROR;
return ret;
}
mCurrentState = MEDIA_RECORDER_PREPARED;
return ret;
}

Related Links

Android check if my lat/lng position withing a given area
I am getting error at the time of starting android eclipse
In Android, what function will be called when my application is killed by other app
Android: Retrieving and Displaying all photos from phone, including gallery and downloads?
getSystemService from non Activity class
how to make logcat not vanish its its previous shown data
Use application module dependancy in library module when using intent
Imported type defined multiple times on Xamarin Android
Multiple clickable items with different actions to perform in ListFragment from SQLite
Why my android application hangs for the first time whenever i install it freshly? [closed]
Android Media Player and List View - Indian Music Sheets
Enabling Remote Access in Apache Tomcat
[Solved]-android ImageView onTouch open soft input keyboard and request focus on EditText (hangouts like)
onItemClick works but onItemLongClick does not, why?
Android responsive UI webapp
App Crash When perform Add record in green dao using async task

Categories

HOME
go
beautifulsoup
flex
saml-2.0
shiro
knitr
switch-statement
telegram-bot
pearson-correlation
banner
boto3
nstableheaderview
google-chrome-app
mxgraph
rtf
naivebayes
openbugs
symmetricds
eip
atlassian
jersey-1.0
gmm
comparator
beta
expressionengine3
fable-f#
bulletphysics
ms-access-web-app
progress-bar
tpm
tizen-tv
uitapgesturerecognizer
zend-debugger
mustache
fstream
hreflang
github3.py
indy10
latitude-longitude
apic
filesystemwatcher
opensmpp
spring-mvc-test
resolution
attributeerror
glm-math
placeholder
strftime
reportservice2010
dtsearch
datamaps
x-ray
remedy
payara-micro
avx
sundials
taocp
chromium-os
actor-platform
ziparchive
nss
contentcontrol
user-management
alloy-ui
bufferedinputstream
node-serialport
jquery-forms-plugin
fits
execve
primitive-types
metatrader5
strawberry-perl
ss7
ios8-extension
multiautocompletetextview
sbcl
ora-06550
mbunit
kogrid
workitem
scmmanager
composite-component
android-sdk-2.3
extreme-programming
fragmenttransaction
cakephp-1.2
extconf.rb
multiplexing
role
fsevents
filemerge
lr
uipagecontrol
load-time
vs-android
hbm2java
addchild
zend-rest
build-environment
silverlight-oob
wcf-instancing
dojo-dnd
information-management
commercial-application
idatareader

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App