'How to get the MediaRecorder setMaxDuration callback?
The MediaRecorder allows for the setting of both duration and file size, but I've yet to figure out how to get the callback event for handling. I've gotten recording up and running by closely following the docs here:
http://developer.android.com/guide/topics/media/camera.html
I've implemented the MediaRecorder.OnInfoListener, which I was guessing would be the one that listened for those two events.
public class CameraActivity extends Activity implements MediaRecorder.OnInfoListener {
/* code here */
}
I added in the duration I want mMediaRecorder.setMaxDuration(5000);
Finally I have put the required callback method for the OnInfo listener, but it never seems to fire.
@Override
public void onInfo(MediaRecorder arg0, int arg1, int arg2) {
Log.i("CALLBACK", "Response Code: " + arg1);
}
Solution 1:[1]
Set MediaRecoder listener as recorder.setOnInfoListener(this); after implementing the MediaRecorder.OnInfoListener interface
To get the maxDuration and maxFileSize callback use the onInfo callback as follows
@Override
public void onInfo(MediaRecorder mr, int what, int extra) {
if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {
Log.e("Maximum Duration Reached","Maximum Duration Reached");
}
if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED) {
Log.e("Maximum File size Reached","Maximum File size Reached");
}
Solution 2:[2]
The likely problem is that you are not assigning a OnInfoListener to your MediaRecorder object.
After initializing your MediaRecorder object call 'setOnInfoListener(X)' and set your listener for variable X.
example:
public class CameraActivity extends Activity implements MediaRecorder.OnInfoListener {
/* some other code */
@Override
public void onInfo(MediaRecorder mediaRecorder, int i, int i1) {
// Maximum Duration Reached
if (i == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {
//DO SOMETHING
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
/* some other code */
// Initialize MediaRecorder and assign listener
MediaRecorder mediaRecorder = new MediaRecorder();
// Required max length
mediaRecorder.setMaxDuration(VAL_MAX_RECORD_LENGTH);
// Set listener for MediaRecorder
mediaRecorder.setOnInfoListener(this);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | akhil nair |
| Solution 2 | Jerry Walton-Pratcher |
