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

The method getChildFragmentManager() is undefined for the type TabMapFragment
Android: HttpResponseCache: retrieve cached content when there is no internet connection?
Creating new Android application project creating src directory with out any activity [duplicate]
How to add image to my FB post update using Facebook SDK? Android
In eclipse activity is not created in manifest [duplicate]
How to create user define function in sqlite and use it in phonegap android
GoogleMap snapshot method returns white image
The response time to a Bluetooth connection between Arduino and Android is proportional to the distance?
Run a method every 5 minutes BuzzBox SDK
Fix actionbar tab width
No armeabi folder
Android back button clicked and var inside of the activity to live longer
Send push-notification from Android to iOS and vice versa?
Setting RelativeLayout rules not working
Can I write an app to play a recording voice when there is an incoming call in android?
android XML file not recognized

Categories

HOME
porting
numbers
apiblueprint
requirements
permissions
vxml
visual-studio-emulator
data-visualization
p2p
google-schemas
appcelerator-studio
plist
mod-security
cmdb
gkturnbasedmatch
shared-libraries
cumulocity
azure-powershell
linear-algebra
symfony-2.8
video-editing
enterprise-miner
cgbitmapcontext
itunes
jquery-multiselect
motion-detection
angularjs-components
mat
ms-access-2003
intersystems-cache
powershell-ise
catch-unit-test
code-snippets
twos-complement
pop3
health-monitoring
demo
apache-stanbol
tasm
visa
claims
xmldocument
clang++
monkey-testing
procfile
opencmis
httrack
libgphoto2
term
podscms
aquamacs
custom-font
check-mk
rxtx
branch-prediction
sandcastle
docpad
parfor
tinkerpop3
model-associations
google-query-language
qbxml
iokit
rewrite
lazybones
batik
jsvc
kubuntu
shopizer
cosine-similarity
viewer
entry-point
tweenlite
lambda-architecture
cfcache
notorm
light
ie8-compatibility-mode
modular
joomla-template
cardreader
web-notifications
mkv
os.system
saxparseexception
update-statement
vs-android
easyb
zen
opml
sifr
django-piston
data-mapping
xpsdocument
sqlobject

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