OSDN Git Service

Implement pause/resume functionality to MediaRecorder
authorWonsik Kim <wonsik@google.com>
Mon, 31 Aug 2015 08:49:21 +0000 (17:49 +0900)
committerWonsik Kim <wonsik@google.com>
Thu, 8 Oct 2015 08:40:34 +0000 (08:40 +0000)
Bug: 20092236
Change-Id: I02b9f11e210d15f6efe52d44f64ad8a3bc566d96

media/java/android/media/MediaRecorder.java
media/jni/android_media_MediaRecorder.cpp

index ed2c4cb..8ac86b0 100644 (file)
@@ -807,6 +807,32 @@ public class MediaRecorder
     public native void stop() throws IllegalStateException;
 
     /**
+     * Pauses recording. Call this after start(). You may resume recording
+     * with resume() without reconfiguration, as opposed to stop(). It does
+     * nothing if the recording is already paused.
+     *
+     * When the recording is paused and resumed, the resulting output would
+     * be as if nothing happend during paused period, immediately switching
+     * to the resumed scene.
+     *
+     * @throws IllegalStateException if it is called before start() or after
+     * stop()
+     * {@hide}
+     */
+    public native void pause() throws IllegalStateException;
+
+    /**
+     * Resumes recording. Call this after start(). It does nothing if the
+     * recording is not paused.
+     *
+     * @throws IllegalStateException if it is called before start() or after
+     * stop()
+     * @see android.media.MediaRecorder#pause
+     * {@hide}
+     */
+    public native void resume() throws IllegalStateException;
+
+    /**
      * Restarts the MediaRecorder to its idle state. After calling
      * this method, you will have to configure it again as if it had just been
      * constructed.
index e05b348..701f7ac 100644 (file)
@@ -399,6 +399,22 @@ android_media_MediaRecorder_stop(JNIEnv *env, jobject thiz)
 }
 
 static void
+android_media_MediaRecorder_pause(JNIEnv *env, jobject thiz)
+{
+    ALOGV("pause");
+    sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
+    process_media_recorder_call(env, mr->pause(), "java/lang/RuntimeException", "pause failed.");
+}
+
+static void
+android_media_MediaRecorder_resume(JNIEnv *env, jobject thiz)
+{
+    ALOGV("resume");
+    sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
+    process_media_recorder_call(env, mr->resume(), "java/lang/RuntimeException", "resume failed.");
+}
+
+static void
 android_media_MediaRecorder_native_reset(JNIEnv *env, jobject thiz)
 {
     ALOGV("native_reset");
@@ -528,6 +544,8 @@ static const JNINativeMethod gMethods[] = {
     {"getMaxAmplitude",      "()I",                             (void *)android_media_MediaRecorder_native_getMaxAmplitude},
     {"start",                "()V",                             (void *)android_media_MediaRecorder_start},
     {"stop",                 "()V",                             (void *)android_media_MediaRecorder_stop},
+    {"pause",                "()V",                             (void *)android_media_MediaRecorder_pause},
+    {"resume",               "()V",                             (void *)android_media_MediaRecorder_resume},
     {"native_reset",         "()V",                             (void *)android_media_MediaRecorder_native_reset},
     {"release",              "()V",                             (void *)android_media_MediaRecorder_release},
     {"native_init",          "()V",                             (void *)android_media_MediaRecorder_native_init},