summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/VideoCamera.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/camera/VideoCamera.java')
-rw-r--r--src/com/android/camera/VideoCamera.java59
1 files changed, 40 insertions, 19 deletions
diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java
index 05e33a6..0479e8b 100644
--- a/src/com/android/camera/VideoCamera.java
+++ b/src/com/android/camera/VideoCamera.java
@@ -67,7 +67,7 @@ import android.widget.TextView;
import android.widget.Toast;
public class VideoCamera extends Activity implements View.OnClickListener,
- ShutterButton.OnShutterButtonListener, SurfaceHolder.Callback {
+ ShutterButton.OnShutterButtonListener, SurfaceHolder.Callback, MediaRecorder.OnErrorListener {
private static final String TAG = "videocamera";
@@ -104,7 +104,6 @@ public class VideoCamera extends Activity implements View.OnClickListener,
private MediaRecorder mMediaRecorder;
private boolean mMediaRecorderRecording = false;
- private boolean mNeedToRegisterRecording;
private long mRecordingStartTime;
// The video file that the hardware camera is about to record into
// (or is recording into.)
@@ -195,16 +194,22 @@ public class VideoCamera extends Activity implements View.OnClickListener,
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
- if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
+ if (action.equals(Intent.ACTION_MEDIA_EJECT)) {
+ mHasSdCard = false;
+ stopVideoRecording();
+ initializeVideo();
+ } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
// SD card available
// TODO put up a "please wait" message
// TODO also listen for the media scanner finished message
updateStorageHint();
mHasSdCard = true;
+ initializeVideo();
} else if (action.equals(Intent.ACTION_MEDIA_UNMOUNTED)) {
// SD card unavailable
updateStorageHint();
mHasSdCard = false;
+ releaseMediaRecorder();
} else if (action.equals(Intent.ACTION_MEDIA_SCANNER_STARTED)) {
Toast.makeText(VideoCamera.this, getResources().getString(R.string.wait), 5000);
} else if (action.equals(Intent.ACTION_MEDIA_SCANNER_FINISHED)) {
@@ -408,6 +413,7 @@ public class VideoCamera extends Activity implements View.OnClickListener,
// install an intent filter to receive SD card related events.
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MEDIA_MOUNTED);
+ intentFilter.addAction(Intent.ACTION_MEDIA_EJECT);
intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
@@ -669,7 +675,6 @@ public class VideoCamera extends Activity implements View.OnClickListener,
}
mMediaRecorder = new MediaRecorder();
- mNeedToRegisterRecording = false;
if (DEBUG_SUPPRESS_AUDIO_RECORDING) {
Log.v(TAG, "DEBUG_SUPPRESS_AUDIO_RECORDING is true.");
@@ -679,18 +684,21 @@ public class VideoCamera extends Activity implements View.OnClickListener,
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
- // We try Uri in intent first. If it doesn't work, use our own instead.
- if (mCameraVideoFileDescriptor != null) {
- mMediaRecorder.setOutputFile(mCameraVideoFileDescriptor);
+ if (!mHasSdCard) {
+ mMediaRecorder.setOutputFile("/dev/null");
} else {
- createVideoPath();
- mMediaRecorder.setOutputFile(mCameraVideoFilename);
+ // We try Uri in intent first. If it doesn't work, use our own instead.
+ if (mCameraVideoFileDescriptor != null) {
+ mMediaRecorder.setOutputFile(mCameraVideoFileDescriptor);
+ } else {
+ createVideoPath();
+ mMediaRecorder.setOutputFile(mCameraVideoFilename);
+ }
}
boolean videoQualityHigh = getBooleanPreference(CameraSettings.KEY_VIDEO_QUALITY,
CameraSettings.DEFAULT_VIDEO_QUALITY_VALUE);
-
if (intent.hasExtra(MediaStore.EXTRA_VIDEO_QUALITY)) {
int extraVideoQuality = intent.getIntExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
videoQualityHigh = (extraVideoQuality > 0);
@@ -849,6 +857,15 @@ public class VideoCamera extends Activity implements View.OnClickListener,
item.setIcon(android.R.drawable.ic_menu_preferences);
}
+ // from MediaRecorder.OnErrorListener
+ public void onError(MediaRecorder mr, int what, int extra) {
+ if (what == MediaRecorder.MEDIA_RECORDER_ERROR_UNKNOWN) {
+ // We may have run out of space on the sdcard.
+ stopVideoRecording();
+ updateStorageHint();
+ }
+ }
+
private void startVideoRecording() {
Log.v(TAG, "startVideoRecording");
if (!mMediaRecorderRecording) {
@@ -859,10 +876,10 @@ public class VideoCamera extends Activity implements View.OnClickListener,
}
// Check mMediaRecorder to see whether it is initialized or not.
- if (mMediaRecorder == null) {
- initializeVideo();
- }
+ if (mMediaRecorder == null) initializeVideo();
+
try {
+ mMediaRecorder.setOnErrorListener(this);
mMediaRecorder.start(); // Recording is now started
} catch (RuntimeException e) {
Log.e(TAG, "Could not start media recorder. ", e);
@@ -932,12 +949,18 @@ public class VideoCamera extends Activity implements View.OnClickListener,
private void stopVideoRecording() {
Log.v(TAG, "stopVideoRecording");
+ boolean needToRegisterRecording = false;
if (mMediaRecorderRecording || mMediaRecorder != null) {
if (mMediaRecorderRecording && mMediaRecorder != null) {
- mMediaRecorder.stop();
+ try {
+ mMediaRecorder.setOnErrorListener(null);
+ mMediaRecorder.stop();
+ } catch (RuntimeException e) {
+ Log.e(TAG, "stop fail: " + e.getMessage());
+ }
mCurrentVideoFilename = mCameraVideoFilename;
Log.v(TAG, "Setting current video filename: " + mCurrentVideoFilename);
- mNeedToRegisterRecording = true;
+ needToRegisterRecording = true;
mMediaRecorderRecording = false;
}
releaseMediaRecorder();
@@ -945,10 +968,8 @@ public class VideoCamera extends Activity implements View.OnClickListener,
mRecordingTimeView.setVisibility(View.GONE);
setScreenTimeoutLong();
}
- if (mNeedToRegisterRecording) {
- registerVideo();
- mNeedToRegisterRecording = false;
- }
+ if (needToRegisterRecording && mHasSdCard) registerVideo();
+
mCameraVideoFilename = null;
mCameraVideoFileDescriptor = null;
}