MediaRecorder.java revision e176ee1222931d67aaea0a3df96262728cc31031
19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/* 29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2007 The Android Open Source Project 39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License. 69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at 79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and 149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License. 159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.media; 189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1903359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhangimport android.annotation.NonNull; 2000a009204e51997249d60eab4f147eff566e2b1fEric Laurentimport android.annotation.SystemApi; 21788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvalaimport android.app.ActivityThread; 229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.hardware.Camera; 239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Handler; 249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Looper; 259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Message; 269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.Log; 279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.view.Surface; 2842419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li 299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.io.FileDescriptor; 3042419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Liimport java.io.IOException; 310d5d3b7cc8b9ff142269a947443c758cb2af4684Robert Shihimport java.io.RandomAccessFile; 329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.lang.ref.WeakReference; 339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/** 359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Used to record audio and video. The recording control is based on a 369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * simple state machine (see below). 379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p><img src="{@docRoot}images/mediarecorder_state_diagram.gif" border="0" /> 399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </p> 409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>A common case of using MediaRecorder to record audio works as follows: 429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <pre>MediaRecorder recorder = new MediaRecorder(); 449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.setOutputFile(PATH_NAME); 489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.prepare(); 499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.start(); // Recording is now started 509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * ... 519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.stop(); 529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.reset(); // You can reuse the object by going back to setAudioSource() step 539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.release(); // Now the object cannot be reused 549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </pre> 559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 569ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * <p>Applications may want to register for informational and error 579ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * events in order to be informed of some internal update and possible 589ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * runtime errors during recording. Registration for such events is 599ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * done by setting the appropriate listeners (via calls 609ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * (to {@link #setOnInfoListener(OnInfoListener)}setOnInfoListener and/or 619ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * {@link #setOnErrorListener(OnErrorListener)}setOnErrorListener). 629ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * In order to receive the respective callback associated with these listeners, 639ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * applications are required to create MediaRecorder objects on threads with a 649ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * Looper running (the main UI thread by default already has a Looper running). 659ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * 6661fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <p><strong>Note:</strong> Currently, MediaRecorder does not work on the emulator. 6761fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * 6861fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <div class="special reference"> 6961fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <h3>Developer Guides</h3> 7061fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <p>For more information about how to use MediaRecorder for recording video, read the 7161fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <a href="{@docRoot}guide/topics/media/camera.html#capture-video">Camera</a> developer guide. 7261fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * For more information about how to use MediaRecorder for recording sound, read the 7361fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <a href="{@docRoot}guide/topics/media/audio-capture.html">Audio Capture</a> developer guide.</p> 7461fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * </div> 759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class MediaRecorder 779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{ 789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project static { 799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project System.loadLibrary("media_jni"); 804935d05eaa306cef88cf0ab13eca386f270409ecMarco Nelissen native_init(); 819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private final static String TAG = "MediaRecorder"; 839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // The two fields below are accessed by native methods 859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @SuppressWarnings("unused") 86075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat private long mNativeContext; 879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @SuppressWarnings("unused") 899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private Surface mSurface; 909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private String mPath; 929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private FileDescriptor mFd; 939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private EventHandler mEventHandler; 949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private OnErrorListener mOnErrorListener; 95ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project private OnInfoListener mOnInfoListener; 969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Default constructor. 999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public MediaRecorder() { 1019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Looper looper; 1039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if ((looper = Looper.myLooper()) != null) { 1049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler = new EventHandler(this, looper); 1059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else if ((looper = Looper.getMainLooper()) != null) { 1069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler = new EventHandler(this, looper); 1079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else { 1089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler = null; 1099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 111788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala String packageName = ActivityThread.currentPackageName(); 1129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Native setup requires a weak reference to our object. 1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * It's easier to create it here than in C++. 1149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 115fbf0ecabac5d7a929628b43ffe8f4f953e47bd54Svetoslav native_setup(new WeakReference<MediaRecorder>(this), packageName, 116fbf0ecabac5d7a929628b43ffe8f4f953e47bd54Svetoslav ActivityThread.currentOpPackageName()); 1179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 120b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * Sets a {@link android.hardware.Camera} to use for recording. 121b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * 122b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * <p>Use this function to switch quickly between preview and capture mode without a teardown of 123b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * the camera object. {@link android.hardware.Camera#unlock()} should be called before 124b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * this. Must call before {@link #prepare}.</p> 1259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param c the Camera to use for recording 127b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * @deprecated Use {@link #getSurface} and the {@link android.hardware.camera2} API instead. 1289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 129b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala @Deprecated 1309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setCamera(Camera c); 1319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 13383cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * Gets the surface to record from when using SURFACE video source. 134b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * 135b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * <p> May only be called after {@link #prepare}. Frames rendered to the Surface before 136b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * {@link #start} will be discarded.</p> 137b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * 138b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * @throws IllegalStateException if it is called before {@link #prepare}, after 139b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * {@link #stop}, or is called when VideoSource is not set to SURFACE. 14083cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * @see android.media.MediaRecorder.VideoSource 14183cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang */ 14283cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang public native Surface getSurface(); 14383cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang 14483cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang /** 14517d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * Configures the recorder to use a persistent surface when using SURFACE video source. 14603359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang * <p> May only be called before {@link #prepare}. If called, {@link #getSurface} should 14703359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang * not be used and will throw IllegalStateException. Frames rendered to the Surface 14803359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang * before {@link #start} will be discarded.</p> 14917d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar 15017d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * @param surface a persistent input surface created by 15117d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * {@link MediaCodec#createPersistentInputSurface} 15203359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang * @throws IllegalStateException if it is called after {@link #prepare} and before 15303359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang * {@link #stop}. 15417d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * @throws IllegalArgumentException if the surface was not created by 15517d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * {@link MediaCodec#createPersistentInputSurface}. 15617d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * @see MediaCodec#createPersistentInputSurface 15717d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * @see MediaRecorder.VideoSource 15817d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar */ 1599560ddb48af0e2da7743452f8d9d6d9cd34d8438Chong Zhang public void setInputSurface(@NonNull Surface surface) { 16003359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang if (!(surface instanceof MediaCodec.PersistentSurface)) { 16103359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang throw new IllegalArgumentException("not a PersistentSurface"); 16203359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang } 1639560ddb48af0e2da7743452f8d9d6d9cd34d8438Chong Zhang native_setInputSurface(surface); 16417d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar } 16517d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar 1669560ddb48af0e2da7743452f8d9d6d9cd34d8438Chong Zhang private native final void native_setInputSurface(@NonNull Surface surface); 16703359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang 16817d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar /** 1699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets a Surface to show a preview of recorded media (video). Calls this 1709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * before prepare() to make sure that the desirable preview display is 171c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * set. If {@link #setCamera(Camera)} is used and the surface has been 172c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * already set to the camera, application do not need to call this. If 173c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * this is called with non-null surface, the preview surface of the camera 174c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * will be replaced by the new surface. If this method is called with null 175c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * surface or not called at all, media recorder will not change the preview 176c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * surface of the camera. 1779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param sv the Surface to use for the preview 179c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * @see android.hardware.Camera#setPreviewDisplay(android.view.SurfaceHolder) 1809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setPreviewDisplay(Surface sv) { 1829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mSurface = sv; 1839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1867af0d66c2270d2b804b029bf33d6d8b532625a74Jean-Michel Trivi * Defines the audio source. 1877af0d66c2270d2b804b029bf33d6d8b532625a74Jean-Michel Trivi * An audio source defines both a default physical source of audio signal, and a recording 188fd3ac3da172b877c6f316de2d066883e7a2d0631Jean-Michel Trivi * configuration. These constants are for instance used 1897af0d66c2270d2b804b029bf33d6d8b532625a74Jean-Michel Trivi * in {@link MediaRecorder#setAudioSource(int)} or 190fd3ac3da172b877c6f316de2d066883e7a2d0631Jean-Michel Trivi * {@link AudioRecord.Builder#setAudioSource(int)}. 1919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final class AudioSource { 193701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi 194701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi private AudioSource() {} 195701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi 196701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi /** @hide */ 197701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi public final static int AUDIO_SOURCE_INVALID = -1; 198701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi 1999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 200b2b292317482d00d067bc91669322b273be61926Rom Lemarchand * in system/media/audio/include/system/audio.h! 2019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2020f0fbd9441f40c6f99470b89774e397f99bf61ebGlenn Kasten 2030f0fbd9441f40c6f99470b89774e397f99bf61ebGlenn Kasten /** Default audio source **/ 2049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT = 0; 2050f0fbd9441f40c6f99470b89774e397f99bf61ebGlenn Kasten 2069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** Microphone audio source */ 2079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int MIC = 1; 2084bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent 209851a8797bd6db96152a7867f4a52b146e25641feEric Laurent /** Voice call uplink (Tx) audio source. 210851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * <p> 211851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * Capturing from <code>VOICE_UPLINK</code> source requires the 212851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * {@link android.Manifest.permission#CAPTURE_AUDIO_OUTPUT} permission. 213851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * This permission is reserved for use by system components and is not available to 214851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * third-party applications. 215851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * </p> 216851a8797bd6db96152a7867f4a52b146e25641feEric Laurent */ 2174bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent public static final int VOICE_UPLINK = 2; 2184bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent 219851a8797bd6db96152a7867f4a52b146e25641feEric Laurent /** Voice call downlink (Rx) audio source. 220851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * <p> 221851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * Capturing from <code>VOICE_DOWNLINK</code> source requires the 222851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * {@link android.Manifest.permission#CAPTURE_AUDIO_OUTPUT} permission. 223851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * This permission is reserved for use by system components and is not available to 224851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * third-party applications. 225851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * </p> 226851a8797bd6db96152a7867f4a52b146e25641feEric Laurent */ 2274bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent public static final int VOICE_DOWNLINK = 3; 2284bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent 229851a8797bd6db96152a7867f4a52b146e25641feEric Laurent /** Voice call uplink + downlink audio source 230851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * <p> 231851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * Capturing from <code>VOICE_CALL</code> source requires the 232851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * {@link android.Manifest.permission#CAPTURE_AUDIO_OUTPUT} permission. 233851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * This permission is reserved for use by system components and is not available to 234851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * third-party applications. 235851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * </p> 236851a8797bd6db96152a7867f4a52b146e25641feEric Laurent */ 2374bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent public static final int VOICE_CALL = 4; 2386869df3a5db0ca0037394f0fd14aecc1d80b5b42Jean-Michel Trivi 2395d1828ee401156cede1d65257d59d66be281edd3Jean-Michel Trivi /** Microphone audio source tuned for video recording, with the same orientation 2405d1828ee401156cede1d65257d59d66be281edd3Jean-Michel Trivi * as the camera if available. */ 2416869df3a5db0ca0037394f0fd14aecc1d80b5b42Jean-Michel Trivi public static final int CAMCORDER = 5; 2426869df3a5db0ca0037394f0fd14aecc1d80b5b42Jean-Michel Trivi 2435d1828ee401156cede1d65257d59d66be281edd3Jean-Michel Trivi /** Microphone audio source tuned for voice recognition. */ 2446869df3a5db0ca0037394f0fd14aecc1d80b5b42Jean-Michel Trivi public static final int VOICE_RECOGNITION = 6; 245820b9e0d3b6f94fe0b524aebf756ce25df273e6aJean-Michel Trivi 246ffd0eb0f1106b0229694a1a86ce7d6356efcf50dJean-Michel Trivi /** Microphone audio source tuned for voice communications such as VoIP. It 247ffd0eb0f1106b0229694a1a86ce7d6356efcf50dJean-Michel Trivi * will for instance take advantage of echo cancellation or automatic gain control 2485d1828ee401156cede1d65257d59d66be281edd3Jean-Michel Trivi * if available. 249820b9e0d3b6f94fe0b524aebf756ce25df273e6aJean-Michel Trivi */ 250820b9e0d3b6f94fe0b524aebf756ce25df273e6aJean-Michel Trivi public static final int VOICE_COMMUNICATION = 7; 25164dfb604e70b70b7c346768114e05ddfadc09addJeff Brown 25264dfb604e70b70b7c346768114e05ddfadc09addJeff Brown /** 25364dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * Audio source for a submix of audio streams to be presented remotely. 25464dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * <p> 25564dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * An application can use this audio source to capture a mix of audio streams 25664dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * that should be transmitted to a remote receiver such as a Wifi display. 25764dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * While recording is active, these audio streams are redirected to the remote 25864dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * submix instead of being played on the device speaker or headset. 25964dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * </p><p> 26064dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * Certain streams are excluded from the remote submix, including 26164dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * {@link AudioManager#STREAM_RING}, {@link AudioManager#STREAM_ALARM}, 26264dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * and {@link AudioManager#STREAM_NOTIFICATION}. These streams will continue 26364dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * to be presented locally as usual. 26464dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * </p><p> 26564dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * Capturing the remote submix audio requires the 26664dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * {@link android.Manifest.permission#CAPTURE_AUDIO_OUTPUT} permission. 26764dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * This permission is reserved for use by system components and is not available to 26864dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * third-party applications. 26964dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * </p> 27064dfb604e70b70b7c346768114e05ddfadc09addJeff Brown */ 27164dfb604e70b70b7c346768114e05ddfadc09addJeff Brown public static final int REMOTE_SUBMIX = 8; 272357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent 273a7cc59c3187711d390c5a483d26c463a1bcbd331rago /** Microphone audio source tuned for unprocessed (raw) sound if available, behaves like 274a7cc59c3187711d390c5a483d26c463a1bcbd331rago * {@link #DEFAULT} otherwise. */ 275a7cc59c3187711d390c5a483d26c463a1bcbd331rago public static final int UNPROCESSED = 9; 276a7cc59c3187711d390c5a483d26c463a1bcbd331rago 277357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent /** 27800a009204e51997249d60eab4f147eff566e2b1fEric Laurent * Audio source for capturing broadcast radio tuner output. 279ce4483cb83afb3a42a32ef2cb00cf04d6f9018fdBenson Huang * @hide 280ce4483cb83afb3a42a32ef2cb00cf04d6f9018fdBenson Huang */ 28100a009204e51997249d60eab4f147eff566e2b1fEric Laurent @SystemApi 28200a009204e51997249d60eab4f147eff566e2b1fEric Laurent public static final int RADIO_TUNER = 1998; 283ce4483cb83afb3a42a32ef2cb00cf04d6f9018fdBenson Huang 284ce4483cb83afb3a42a32ef2cb00cf04d6f9018fdBenson Huang /** 285357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * Audio source for preemptible, low-priority software hotword detection 286357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * It presents the same gain and pre processing tuning as {@link #VOICE_RECOGNITION}. 287357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * <p> 288357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * An application should use this audio source when it wishes to do 289357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * always-on software hotword detection, while gracefully giving in to any other application 290357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * that might want to read from the microphone. 291357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * </p> 292357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * This is a hidden audio source. 293357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * @hide 294357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent */ 29500a009204e51997249d60eab4f147eff566e2b1fEric Laurent @SystemApi 29600a009204e51997249d60eab4f147eff566e2b1fEric Laurent public static final int HOTWORD = 1999; 2979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 2989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 299dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi // TODO make AudioSource static (API change) and move this method inside the AudioSource class 300dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi /** 301dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi * @hide 302dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi * @param source An audio source to test 303dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi * @return true if the source is only visible to system components 304dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi */ 305dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi public static boolean isSystemOnlyAudioSource(int source) { 306dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi switch(source) { 307dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.DEFAULT: 308dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.MIC: 309dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.VOICE_UPLINK: 310dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.VOICE_DOWNLINK: 311dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.VOICE_CALL: 312dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.CAMCORDER: 313dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.VOICE_RECOGNITION: 314dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.VOICE_COMMUNICATION: 315dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi //case REMOTE_SUBMIX: considered "system" as it requires system permissions 316dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.UNPROCESSED: 317dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi return false; 318dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi default: 319dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi return true; 320dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi } 321dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi } 322dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi 3239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Defines the video source. These constants are used with 3259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link MediaRecorder#setVideoSource(int)}. 3269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final class VideoSource { 3289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 3299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediarecorder.h! 3309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private VideoSource() {} 3329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT = 0; 33383cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang /** Camera video source 33483cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * <p> 335b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * Using the {@link android.hardware.Camera} API as video source. 33683cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * </p> 33783cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang */ 3389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int CAMERA = 1; 33983cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang /** Surface video source 34083cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * <p> 34183cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * Using a Surface as video source. 34283cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * </p><p> 34383cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * This flag must be used when recording from an 344b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * {@link android.hardware.camera2} API source. 34583cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * </p><p> 34683cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * When using this video source type, use {@link MediaRecorder#getSurface()} 34783cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * to retrieve the surface created by MediaRecorder. 34883cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang */ 34983cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang public static final int SURFACE = 2; 3509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Defines the output format. These constants are used with 3549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link MediaRecorder#setOutputFormat(int)}. 3559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final class OutputFormat { 3579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 3589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediarecorder.h! 3599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private OutputFormat() {} 3619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT = 0; 3629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3GPP media file format*/ 3639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int THREE_GPP = 1; 3649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** MPEG4 media file format*/ 3659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int MPEG_4 = 2; 3662bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang 367874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong /** The following formats are audio only .aac or .amr formats */ 368874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong 369874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong /** 370874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong * AMR NB file format 371874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong * @deprecated Deprecated in favor of MediaRecorder.OutputFormat.AMR_NB 372874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong */ 3739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int RAW_AMR = 3; 374874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong 3752116dc91e96f7153f65468ed40a0b57e437679f7James Dong /** AMR NB file format */ 3762bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AMR_NB = 3; 377874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong 3782116dc91e96f7153f65468ed40a0b57e437679f7James Dong /** AMR WB file format */ 3792bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AMR_WB = 4; 380874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong 3812bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang /** @hide AAC ADIF file format */ 3822bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AAC_ADIF = 5; 383874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong 384874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong /** AAC ADTS file format */ 3852bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AAC_ADTS = 6; 38657648e4eec7dd2593af467877bc7cce4aa654759Andreas Huber 38757648e4eec7dd2593af467877bc7cce4aa654759Andreas Huber /** @hide Stream over a socket, limited to a single stream */ 38857648e4eec7dd2593af467877bc7cce4aa654759Andreas Huber public static final int OUTPUT_FORMAT_RTP_AVP = 7; 3899adf466021d37a5062d7d3361e14bfd9e7ffeba6Andreas Huber 3905b168a0c549a164898b5f1568b155d02ccce77cdHangyu Kuang /** H.264/AAC data encapsulated in MPEG2/TS */ 3915b168a0c549a164898b5f1568b155d02ccce77cdHangyu Kuang public static final int MPEG_2_TS = 8; 392c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih 393c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih /** VP8/VORBIS data in a WEBM container */ 394c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih public static final int WEBM = 9; 3959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project }; 3969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Defines the audio encoding. These constants are used with 3999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link MediaRecorder#setAudioEncoder(int)}. 4009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final class AudioEncoder { 4029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 4039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediarecorder.h! 4049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private AudioEncoder() {} 4069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT = 0; 4079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** AMR (Narrowband) audio codec */ 4089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AMR_NB = 1; 4092116dc91e96f7153f65468ed40a0b57e437679f7James Dong /** AMR (Wideband) audio codec */ 4102bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AMR_WB = 2; 411ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke /** AAC Low Complexity (AAC-LC) audio codec */ 4122bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AAC = 3; 413ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke /** High Efficiency AAC (HE-AAC) audio codec */ 414ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke public static final int HE_AAC = 4; 415ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke /** Enhanced Low Delay AAC (AAC-ELD) audio codec */ 416ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke public static final int AAC_ELD = 5; 417c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih /** Ogg Vorbis audio codec */ 418c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih public static final int VORBIS = 6; 4199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Defines the video encoding. These constants are used with 4239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link MediaRecorder#setVideoEncoder(int)}. 4249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final class VideoEncoder { 4269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 4279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediarecorder.h! 4289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private VideoEncoder() {} 4309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT = 0; 4319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int H263 = 1; 4329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int H264 = 2; 4339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int MPEG_4_SP = 3; 434c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih public static final int VP8 = 4; 435886e562bc5aa51b1bbb3f429a440d1f4e90db1c2Wonsik Kim public static final int HEVC = 5; 4369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the audio source to be used for recording. If this method is not 4409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * called, the output file will not contain an audio track. The source needs 4419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to be specified before setting recording-parameters or encoders. Call 4429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this only before setOutputFormat(). 4439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 4449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param audio_source the audio source to use 4459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after setOutputFormat() 4469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.AudioSource 4479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setAudioSource(int audio_source) 4499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 4509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4524bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent * Gets the maximum value for audio sources. 4534bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent * @see android.media.MediaRecorder.AudioSource 4544bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent */ 4552ac2afeac989ea1dc326b0db996d6c6c8e00cc29Jean-Michel Trivi public static final int getAudioSourceMax() { 456a7cc59c3187711d390c5a483d26c463a1bcbd331rago return AudioSource.UNPROCESSED; 4572ac2afeac989ea1dc326b0db996d6c6c8e00cc29Jean-Michel Trivi } 4584bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent 4594bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent /** 4609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the video source to be used for recording. If this method is not 4619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * called, the output file will not contain an video track. The source needs 4629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to be specified before setting recording-parameters or encoders. Call 4639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this only before setOutputFormat(). 4649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 4659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param video_source the video source to use 4669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after setOutputFormat() 4679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.VideoSource 4689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setVideoSource(int video_source) 4709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 4719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 473e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong * Uses the settings from a CamcorderProfile object for recording. This method should 474e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong * be called after the video AND audio sources are set, and before setOutputFile(). 475a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * If a time lapse CamcorderProfile is used, audio related source or recording 476a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * parameters are ignored. 477e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong * 478e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong * @param profile the CamcorderProfile to use 479e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong * @see android.media.CamcorderProfile 480e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong */ 481e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong public void setProfile(CamcorderProfile profile) { 482e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong setOutputFormat(profile.fileFormat); 483e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong setVideoFrameRate(profile.videoFrameRate); 484e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight); 485e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong setVideoEncodingBitRate(profile.videoBitRate); 486e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong setVideoEncoder(profile.videoCodec); 4874f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra if (profile.quality >= CamcorderProfile.QUALITY_TIME_LAPSE_LOW && 48833fe290ca33235d7e0988cace14de3319a9a83f1James Dong profile.quality <= CamcorderProfile.QUALITY_TIME_LAPSE_QVGA) { 489a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong // Nothing needs to be done. Call to setCaptureRate() enables 490a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong // time lapse video recording. 4914f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra } else { 4924f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra setAudioEncodingBitRate(profile.audioBitRate); 4934f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra setAudioChannels(profile.audioChannels); 4944f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra setAudioSamplingRate(profile.audioSampleRate); 4954f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra setAudioEncoder(profile.audioCodec); 4964f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra } 497e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong } 498e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong 499e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong /** 5004f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * Set video frame capture rate. This can be used to set a different video frame capture 501a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * rate than the recorded video's playback rate. This method also sets the recording mode 502a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * to time lapse. In time lapse video recording, only video is recorded. Audio related 503a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * parameters are ignored when a time lapse recording session starts, if an application 504a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * sets them. 505ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra * 5064f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * @param fps Rate at which frames should be captured in frames per second. 5074f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * The fps can go as low as desired. However the fastest fps will be limited by the hardware. 5084f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * For resolutions that can be captured by the video camera, the fastest fps can be computed using 5094f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * {@link android.hardware.Camera.Parameters#getPreviewFpsRange(int[])}. For higher 5104f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * resolutions the fastest fps may be more restrictive. 5114f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * Note that the recorder cannot guarantee that frames will be captured at the 5124f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * given rate due to camera/encoder limitations. However it tries to be as close as 5134f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * possible. 514ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra */ 5154f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra public void setCaptureRate(double fps) { 516a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong // Make sure that time lapse is enabled when this method is called. 5171c7928e8c68654d087f83c7cefc59095950b8befJohan Redestig setParameter("time-lapse-enable=1"); 518fbdee2c04b88210bab5c9a769908be42d1775e16Chong Zhang setParameter("time-lapse-fps=" + fps); 519ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra } 520ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra 521ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra /** 522ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * Sets the orientation hint for output video playback. 5235aa95dd36cd0708d25accd8d745ae8ebc255758fJames Dong * This method should be called before prepare(). This method will not 524ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * trigger the source video frame to rotate during video recording, but to 525ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * add a composition matrix containing the rotation angle in the output 526ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * video if the output format is OutputFormat.THREE_GPP or 527ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * OutputFormat.MPEG_4 so that a video player can choose the proper 528ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * orientation for playback. Note that some video players may choose 529ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * to ignore the compostion matrix in a video during playback. 530ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * 531ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * @param degrees the angle to be rotated clockwise in degrees. 532ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * The supported angles are 0, 90, 180, and 270 degrees. 533ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * @throws IllegalArgumentException if the angle is not supported. 534ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * 535ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong */ 536ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong public void setOrientationHint(int degrees) { 537ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong if (degrees != 0 && 538ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong degrees != 90 && 539ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong degrees != 180 && 540ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong degrees != 270) { 541ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong throw new IllegalArgumentException("Unsupported angle: " + degrees); 542ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong } 5432450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund setParameter("video-param-rotation-angle-degrees=" + degrees); 544ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong } 545ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong 546ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong /** 547af3131fe2e20c7b5e080d098a3b6847c5414bcaeJames Dong * Set and store the geodata (latitude and longitude) in the output file. 548987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * This method should be called before prepare(). The geodata is 549987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * stored in udta box if the output format is OutputFormat.THREE_GPP 550987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * or OutputFormat.MPEG_4, and is ignored for other output formats. 551987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * The geodata is stored according to ISO-6709 standard. 552987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * 553987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * @param latitude latitude in degrees. Its value must be in the 554987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * range [-90, 90]. 555987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * @param longitude longitude in degrees. Its value must be in the 556987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * range [-180, 180]. 557987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * 558987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * @throws IllegalArgumentException if the given latitude or 559987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * longitude is out of range. 560987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * 561987ab4833ecbafbdf750eb1b04e43693433c4783James Dong */ 562af3131fe2e20c7b5e080d098a3b6847c5414bcaeJames Dong public void setLocation(float latitude, float longitude) { 563987ab4833ecbafbdf750eb1b04e43693433c4783James Dong int latitudex10000 = (int) (latitude * 10000 + 0.5); 564987ab4833ecbafbdf750eb1b04e43693433c4783James Dong int longitudex10000 = (int) (longitude * 10000 + 0.5); 565987ab4833ecbafbdf750eb1b04e43693433c4783James Dong 566987ab4833ecbafbdf750eb1b04e43693433c4783James Dong if (latitudex10000 > 900000 || latitudex10000 < -900000) { 567af3131fe2e20c7b5e080d098a3b6847c5414bcaeJames Dong String msg = "Latitude: " + latitude + " out of range."; 568987ab4833ecbafbdf750eb1b04e43693433c4783James Dong throw new IllegalArgumentException(msg); 569987ab4833ecbafbdf750eb1b04e43693433c4783James Dong } 570987ab4833ecbafbdf750eb1b04e43693433c4783James Dong if (longitudex10000 > 1800000 || longitudex10000 < -1800000) { 571af3131fe2e20c7b5e080d098a3b6847c5414bcaeJames Dong String msg = "Longitude: " + longitude + " out of range"; 572987ab4833ecbafbdf750eb1b04e43693433c4783James Dong throw new IllegalArgumentException(msg); 573987ab4833ecbafbdf750eb1b04e43693433c4783James Dong } 574987ab4833ecbafbdf750eb1b04e43693433c4783James Dong 575987ab4833ecbafbdf750eb1b04e43693433c4783James Dong setParameter("param-geotag-latitude=" + latitudex10000); 576987ab4833ecbafbdf750eb1b04e43693433c4783James Dong setParameter("param-geotag-longitude=" + longitudex10000); 577987ab4833ecbafbdf750eb1b04e43693433c4783James Dong } 578987ab4833ecbafbdf750eb1b04e43693433c4783James Dong 579987ab4833ecbafbdf750eb1b04e43693433c4783James Dong /** 5809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the format of the output file produced during recording. Call this 5819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * after setAudioSource()/setVideoSource() but before prepare(). 5829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 5832170312ab0b6766e8b73b806efbe6abdbb702bbcDave Sparks * <p>It is recommended to always use 3GP format when using the H.263 5842170312ab0b6766e8b73b806efbe6abdbb702bbcDave Sparks * video encoder and AMR audio encoder. Using an MPEG-4 container format 5852170312ab0b6766e8b73b806efbe6abdbb702bbcDave Sparks * may confuse some desktop players.</p> 5862170312ab0b6766e8b73b806efbe6abdbb702bbcDave Sparks * 5879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param output_format the output format to use. The output format 5889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * needs to be specified before setting recording-parameters or encoders. 5899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after prepare() or before 5909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setAudioSource()/setVideoSource(). 5919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.OutputFormat 5929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setOutputFormat(int output_format) 5949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 5959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the width and height of the video to be captured. Must be called 5989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * after setVideoSource(). Call this after setOutFormat() but before 5999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * prepare(). 6009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param width the width of the video to be captured 6029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param height the height of the video to be captured 6039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after 6049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * prepare() or before setOutputFormat() 6059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setVideoSize(int width, int height) 6079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 6089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the frame rate of the video to be captured. Must be called 6119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * after setVideoSource(). Call this after setOutFormat() but before 6129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * prepare(). 6139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param rate the number of frames per second of video to capture 6159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after 6169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * prepare() or before setOutputFormat(). 6179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * NOTE: On some devices that have auto-frame rate, this sets the 6199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * maximum frame rate, not a constant frame rate. Actual frame rate 6209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * will vary according to lighting conditions. 6219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setVideoFrameRate(int rate) throws IllegalStateException; 6239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 625ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * Sets the maximum duration (in ms) of the recording session. 626ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * Call this after setOutFormat() but before prepare(). 627105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * After recording reaches the specified duration, a notification 628105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * will be sent to the {@link android.media.MediaRecorder.OnInfoListener} 629105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * with a "what" code of {@link #MEDIA_RECORDER_INFO_MAX_DURATION_REACHED} 630105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * and recording will be stopped. Stopping happens asynchronously, there 631105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * is no guarantee that the recorder will have stopped by the time the 632105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * listener is notified. 633ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * 634ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * @param max_duration_ms the maximum duration in ms (if zero or negative, disables the duration limit) 635ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * 636ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 637ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project public native void setMaxDuration(int max_duration_ms) throws IllegalArgumentException; 638ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 639ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /** 640105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * Sets the maximum filesize (in bytes) of the recording session. 641105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * Call this after setOutFormat() but before prepare(). 642105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * After recording reaches the specified filesize, a notification 643105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * will be sent to the {@link android.media.MediaRecorder.OnInfoListener} 644105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * with a "what" code of {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED} 645105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * and recording will be stopped. Stopping happens asynchronously, there 646105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * is no guarantee that the recorder will have stopped by the time the 647105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * listener is notified. 648105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * 649105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * @param max_filesize_bytes the maximum filesize in bytes (if zero or negative, disables the limit) 650105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * 651105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project */ 652105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project public native void setMaxFileSize(long max_filesize_bytes) throws IllegalArgumentException; 653105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project 654105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project /** 6559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the audio encoder to be used for recording. If this method is not 6569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * called, the output file will not contain an audio track. Call this after 6579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() but before prepare(). 6589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param audio_encoder the audio encoder to use. 6609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 6619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() or after prepare(). 6629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.AudioEncoder 6639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setAudioEncoder(int audio_encoder) 6659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 6669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the video encoder to be used for recording. If this method is not 6699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * called, the output file will not contain an video track. Call this after 6709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() and before prepare(). 6719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param video_encoder the video encoder to use. 6739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 6749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() or after prepare() 6759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.VideoEncoder 6769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setVideoEncoder(int video_encoder) 6789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 6799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6810fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Sets the audio sampling rate for recording. Call this method before prepare(). 6820fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Prepare() may perform additional checks on the parameter to make sure whether 6830fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * the specified audio sampling rate is applicable. The sampling rate really depends 6840fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * on the format for the audio recording, as well as the capabilities of the platform. 6850fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * For instance, the sampling rate supported by AAC audio coding standard ranges 68654815a78aff9bd453a8f0ac3c02f3a35c4b04146James Dong * from 8 to 96 kHz, the sampling rate supported by AMRNB is 8kHz, and the sampling 68754815a78aff9bd453a8f0ac3c02f3a35c4b04146James Dong * rate supported by AMRWB is 16kHz. Please consult with the related audio coding 68854815a78aff9bd453a8f0ac3c02f3a35c4b04146James Dong * standard for the supported audio sampling rate. 6890fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * 6900fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * @param samplingRate the sampling rate for audio in samples per second. 6910fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong */ 6920fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong public void setAudioSamplingRate(int samplingRate) { 6930fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong if (samplingRate <= 0) { 6940fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong throw new IllegalArgumentException("Audio sampling rate is not positive"); 6950fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 6962450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund setParameter("audio-param-sampling-rate=" + samplingRate); 6970fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 6980fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong 6990fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong /** 7000fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Sets the number of audio channels for recording. Call this method before prepare(). 7010fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Prepare() may perform additional checks on the parameter to make sure whether the 7020fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * specified number of audio channels are applicable. 7032bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang * 7040fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * @param numChannels the number of audio channels. Usually it is either 1 (mono) or 2 7050fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * (stereo). 7062bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang */ 7070fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong public void setAudioChannels(int numChannels) { 7080fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong if (numChannels <= 0) { 7090fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong throw new IllegalArgumentException("Number of channels is not positive"); 7100fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7112450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund setParameter("audio-param-number-of-channels=" + numChannels); 7120fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7130fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong 7140fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong /** 7150fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Sets the audio encoding bit rate for recording. Call this method before prepare(). 7160fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Prepare() may perform additional checks on the parameter to make sure whether the 7170fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * specified bit rate is applicable, and sometimes the passed bitRate will be clipped 7180fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * internally to ensure the audio recording can proceed smoothly based on the 7190fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * capabilities of the platform. 7200fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * 7210fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * @param bitRate the audio encoding bit rate in bits per second. 7220fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong */ 7230fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong public void setAudioEncodingBitRate(int bitRate) { 7240fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong if (bitRate <= 0) { 7250fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong throw new IllegalArgumentException("Audio encoding bit rate is not positive"); 7260fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7272450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund setParameter("audio-param-encoding-bitrate=" + bitRate); 7280fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7290fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong 7300fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong /** 7310fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Sets the video encoding bit rate for recording. Call this method before prepare(). 7320fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Prepare() may perform additional checks on the parameter to make sure whether the 7330fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * specified bit rate is applicable, and sometimes the passed bitRate will be 7340fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * clipped internally to ensure the video recording can proceed smoothly based on 7350fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * the capabilities of the platform. 7360fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * 7370fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * @param bitRate the video encoding bit rate in bits per second. 7380fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong */ 7390fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong public void setVideoEncodingBitRate(int bitRate) { 7400fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong if (bitRate <= 0) { 7410fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong throw new IllegalArgumentException("Video encoding bit rate is not positive"); 7420fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7432450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund setParameter("video-param-encoding-bitrate=" + bitRate); 7440fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7452bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang 7462bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang /** 747f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * Sets the video encoding profile for recording. Call this method before prepare(). 748f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * Prepare() may perform additional checks on the parameter to make sure whether the 749f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * specified profile and level are applicable, and sometimes the passed profile or 750f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * level will be discarded due to codec capablity or to ensure the video recording 751f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * can proceed smoothly based on the capabilities of the platform. 752f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * @hide 753f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * @param profile declared in {@link MediaCodecInfo.CodecProfileLevel}. 754f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * @param level declared in {@link MediaCodecInfo.CodecProfileLevel}. 755f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang */ 756f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang public void setVideoEncodingProfileLevel(int profile, int level) { 757f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang if (profile <= 0) { 758f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang throw new IllegalArgumentException("Video encoding profile is not positive"); 759f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang } 760f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang if (level <= 0) { 761f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang throw new IllegalArgumentException("Video encoding level is not positive"); 762f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang } 763f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang setParameter("video-param-encoder-profile=" + profile); 764f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang setParameter("video-param-encoder-level=" + level); 765f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang } 766f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang 767f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang /** 7683ff98beeafd271a65c1f824699431366882b04f6James Dong * Currently not implemented. It does nothing. 7693ff98beeafd271a65c1f824699431366882b04f6James Dong * @deprecated Time lapse mode video recording using camera still image capture 7703ff98beeafd271a65c1f824699431366882b04f6James Dong * is not desirable, and will not be supported. 771029d7e15f38cdd3c1941a16186c5941edc85bc3dJames Dong * @hide 772b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra */ 7731fec21be65ddda46fe39c40e00d2fb94a8ce59f1Nipun Kwatra public void setAuxiliaryOutputFile(FileDescriptor fd) 774b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra { 7753ff98beeafd271a65c1f824699431366882b04f6James Dong Log.w(TAG, "setAuxiliaryOutputFile(FileDescriptor) is no longer supported."); 776b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra } 777b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra 778b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra /** 7793ff98beeafd271a65c1f824699431366882b04f6James Dong * Currently not implemented. It does nothing. 7803ff98beeafd271a65c1f824699431366882b04f6James Dong * @deprecated Time lapse mode video recording using camera still image capture 7813ff98beeafd271a65c1f824699431366882b04f6James Dong * is not desirable, and will not be supported. 782029d7e15f38cdd3c1941a16186c5941edc85bc3dJames Dong * @hide 783b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra */ 7841fec21be65ddda46fe39c40e00d2fb94a8ce59f1Nipun Kwatra public void setAuxiliaryOutputFile(String path) 785b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra { 7863ff98beeafd271a65c1f824699431366882b04f6James Dong Log.w(TAG, "setAuxiliaryOutputFile(String) is no longer supported."); 787b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra } 788b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra 789b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra /** 7909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Pass in the file descriptor of the file to be written. Call this after 7919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() but before prepare(). 7929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 7939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param fd an open file descriptor to be written into. 7949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 7959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() or after prepare() 7969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 7979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setOutputFile(FileDescriptor fd) throws IllegalStateException 7989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 7999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mPath = null; 8009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mFd = fd; 8019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 8039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 804e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * Sets the next output file descriptor to be used when the maximum filesize is reached 805e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * on the prior output {@link #setOutputFile} or {@link #setNextOutputFile}). File descriptor 806e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * must be seekable and in read-write mode. After setting the next output file, application 807e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * should not use the file referenced by this file descriptor until {@link #stop}. Application 808e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * must call this after receiving on the {@link android.media.MediaRecorder.OnInfoListener} a 809e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * "what" code of {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING} and before receiving 810e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * a "what" code of {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED}. The file is not used 811e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * until switching to that output. Application will receive 812e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * {@link #MEDIA_RECORDER_INFO_NEXT_OUTPUT_FILE_STARTED} when the next output file is used. 813e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * Application will not be able to set a new output file if the previous one has not been used. 814e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * Application is responsible for cleaning up unused files after {@link #stop} is called. 815e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * 816e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @param fd an open file descriptor to be written into. 817e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @throws IllegalStateException if it is called before prepare(). 818e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @throws IOException if setNextOutputFile fails otherwise. 819e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang */ 820e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang public void setNextOutputFile(FileDescriptor fd) throws IllegalStateException, IOException 821e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang { 822e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang _setNextOutputFile(fd); 823e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang } 824e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang 825e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang /** 8269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the path of the output file to be produced. Call this after 8279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() but before prepare(). 8289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 8299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param path The pathname to use. 8309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 8319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() or after prepare() 8329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 8339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setOutputFile(String path) throws IllegalStateException 8349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 8359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mFd = null; 8369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mPath = path; 8379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 839e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang /** 840e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * Sets the next output file path to be used when the maximum filesize is reached 841e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * on the prior output {@link #setOutputFile} or {@link #setNextOutputFile}). File should 842e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * be seekable. After setting the next output file, application should not use the file 843e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * referenced by this file descriptor until {@link #stop}. Application must call this 844e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * after receiving on the {@link android.media.MediaRecorder.OnInfoListener} a "what" code of 845e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING} and before receiving a "what" code of 846e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED}. The file is not used until switching to 847e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * that output. Application will receive {@link #MEDIA_RECORDER_INFO_NEXT_OUTPUT_FILE_STARTED} 848e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * when the next output file is used. Application will not be able to set a new output file if 849e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * the previous one has not been used. Application is responsible for cleaning up unused files 850e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * after {@link #stop} is called. 851e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * 852e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @param path The pathname to use. 853e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @throws IllegalStateException if it is called before prepare(). 854e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @throws IOException if setNextOutputFile fails otherwise. 855e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang */ 856e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang public void setNextOutputFile(String path) throws IllegalStateException, IOException 857e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang { 858e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang if (path != null) { 859e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang RandomAccessFile file = new RandomAccessFile(path, "rws"); 860e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang try { 861e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang _setNextOutputFile(file.getFD()); 862e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang } finally { 863e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang file.close(); 864e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang } 865e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang } 866e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang } 867e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang 8689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // native implementation 869e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang private native void _setOutputFile(FileDescriptor fd) throws IllegalStateException, IOException; 870e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang private native void _setNextOutputFile(FileDescriptor fd) throws IllegalStateException, IOException; 8719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native void _prepare() throws IllegalStateException, IOException; 8729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 8739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 8749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Prepares the recorder to begin capturing and encoding data. This method 8759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * must be called after setting up the desired audio and video sources, 8769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * encoders, file format, etc., but before start(). 8779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 8789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after 8799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * start() or before setOutputFormat(). 8809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IOException if prepare fails otherwise. 8819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 8829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void prepare() throws IllegalStateException, IOException 8839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 8849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mPath != null) { 8850d5d3b7cc8b9ff142269a947443c758cb2af4684Robert Shih RandomAccessFile file = new RandomAccessFile(mPath, "rws"); 8869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 887e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang _setOutputFile(file.getFD()); 8889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } finally { 8890d5d3b7cc8b9ff142269a947443c758cb2af4684Robert Shih file.close(); 8909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else if (mFd != null) { 892e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang _setOutputFile(mFd); 8939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else { 8949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throw new IOException("No valid output file"); 8959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 896b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra 8979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project _prepare(); 8989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Begins capturing and encoding data to the file specified with 9029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFile(). Call this after prepare(). 9039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 90442419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * <p>Since API level 13, if applications set a camera via 90542419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * {@link #setCamera(Camera)}, the apps can use the camera after this method 906528b084be26ff6f5b5d8cf42007bf964857be8daWu-cheng Li * call. The apps do not need to lock the camera again. However, if this 907528b084be26ff6f5b5d8cf42007bf964857be8daWu-cheng Li * method fails, the apps should still lock the camera back. The apps should 908528b084be26ff6f5b5d8cf42007bf964857be8daWu-cheng Li * not start another recording session during recording. 90942419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * 9109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 9119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * prepare(). 9129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void start() throws IllegalStateException; 9149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Stops recording. Call this after start(). Once recording is stopped, 9179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you will have to configure it again as if it has just been constructed. 91822bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * Note that a RuntimeException is intentionally thrown to the 91922bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * application, if no valid audio/video data has been received when stop() 92022bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * is called. This happens if stop() is called immediately after 92122bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * start(). The failure lets the application take action accordingly to 92222bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * clean up the output file (delete the output file, for instance), since 92322bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * the output file is not properly constructed when this happens. 9249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 9259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before start() 9269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void stop() throws IllegalStateException; 9289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 93083995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * Pauses recording. Call this after start(). You may resume recording 93183995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * with resume() without reconfiguration, as opposed to stop(). It does 93283995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * nothing if the recording is already paused. 93383995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * 93483995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * When the recording is paused and resumed, the resulting output would 93583995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * be as if nothing happend during paused period, immediately switching 93683995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * to the resumed scene. 93783995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * 93883995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * @throws IllegalStateException if it is called before start() or after 93983995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * stop() 94083995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim */ 94183995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim public native void pause() throws IllegalStateException; 94283995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim 94383995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim /** 94483995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * Resumes recording. Call this after start(). It does nothing if the 94583995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * recording is not paused. 94683995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * 94783995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * @throws IllegalStateException if it is called before start() or after 94883995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * stop() 94983995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * @see android.media.MediaRecorder#pause 95083995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim */ 95183995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim public native void resume() throws IllegalStateException; 95283995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim 95383995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim /** 9549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Restarts the MediaRecorder to its idle state. After calling 9559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this method, you will have to configure it again as if it had just been 9569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * constructed. 9579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void reset() { 9599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_reset(); 9609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // make sure none of the listeners get called anymore 9629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler.removeCallbacksAndMessages(null); 9639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native void native_reset(); 9669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the maximum absolute amplitude that was sampled since the last 9699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * call to this method. Call this only after the setAudioSource(). 9709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 9719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the maximum absolute amplitude measured since the last call, or 9729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 0 when called for the first time 9739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 9749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the audio source has been set. 9759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native int getMaxAmplitude() throws IllegalStateException; 9779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change this value without updating its counterpart 979a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong * in include/media/mediarecorder.h or mediaplayer.h! 9809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** Unspecified media recorder error. 9829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.OnErrorListener 9839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int MEDIA_RECORDER_ERROR_UNKNOWN = 1; 985a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong /** Media server died. In this case, the application must release the 986a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong * MediaRecorder object and instantiate a new one. 987a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong * @see android.media.MediaRecorder.OnErrorListener 988a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong */ 989a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong public static final int MEDIA_ERROR_SERVER_DIED = 100; 9909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Interface definition for a callback to be invoked when an error 9939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * occurs while recording. 9949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public interface OnErrorListener 9969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 9979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Called when an error occurs while recording. 9992bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang * 10009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param mr the MediaRecorder that encountered the error 10019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param what the type of error that has occurred: 10029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ul> 10039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>{@link #MEDIA_RECORDER_ERROR_UNKNOWN} 1004a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong * <li>{@link #MEDIA_ERROR_SERVER_DIED} 10059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ul> 10069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param extra an extra code, specific to the error type 10079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project void onError(MediaRecorder mr, int what, int extra); 10099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 10129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Register a callback to be invoked when an error occurs while 10139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recording. 10149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 10159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param l the callback that will be run 10169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setOnErrorListener(OnErrorListener l) 10189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 10199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnErrorListener = l; 10209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1022ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /* Do not change these values without updating their counterparts 1023ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * in include/media/mediarecorder.h! 1024ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 10256f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih /** Unspecified media recorder info. 1026ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * @see android.media.MediaRecorder.OnInfoListener 1027ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 1028ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project public static final int MEDIA_RECORDER_INFO_UNKNOWN = 1; 1029ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /** A maximum duration had been setup and has now been reached. 1030ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * @see android.media.MediaRecorder.OnInfoListener 1031ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 1032ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project public static final int MEDIA_RECORDER_INFO_MAX_DURATION_REACHED = 800; 1033105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project /** A maximum filesize had been setup and has now been reached. 1034e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * Note: This event will not be sent if application already set 1035e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * next output file through {@link #setNextOutputFile}. 1036105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * @see android.media.MediaRecorder.OnInfoListener 1037105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project */ 1038105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project public static final int MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED = 801; 1039e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang /** A maximum filesize had been setup and current recorded file size 1040e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * has reached 90% of the limit. This is sent once per file upon 1041e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * reaching/passing the 90% limit. To continue the recording, applicaiton 1042e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * should use {@link #setNextOutputFile} to set the next output file. 1043e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * Otherwise, recording will stop when reaching maximum file size. 1044e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @see android.media.MediaRecorder.OnInfoListener 1045e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang */ 1046e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang public static final int MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING = 802; 1047e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang /** A maximum filesize had been reached and MediaRecorder has switched 1048e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * output to a new file set by application {@link #setNextOutputFile}. 1049e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * For best practice, application should use this event to keep track 1050e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * of whether the file previously set has been used or not. 1051e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @see android.media.MediaRecorder.OnInfoListener 1052e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang */ 1053e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang public static final int MEDIA_RECORDER_INFO_NEXT_OUTPUT_FILE_STARTED = 803; 1054ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 10559e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** informational events for individual tracks, for testing purpose. 10569e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * The track informational event usually contains two parts in the ext1 10579e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * arg of the onInfo() callback: bit 31-28 contains the track id; and 10589e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * the rest of the 28 bits contains the informational event defined here. 10599e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * For example, ext1 = (1 << 28 | MEDIA_RECORDER_TRACK_INFO_TYPE) if the 10609e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * track id is 1 for informational event MEDIA_RECORDER_TRACK_INFO_TYPE; 10619e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * while ext1 = (0 << 28 | MEDIA_RECORDER_TRACK_INFO_TYPE) if the track 10629e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * id is 0 for informational event MEDIA_RECORDER_TRACK_INFO_TYPE. The 10639e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * application should extract the track id and the type of informational 10649e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * event from ext1, accordingly. 10659e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * 10669e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * FIXME: 10679e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * Please update the comment for onInfo also when these 10689e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * events are unhidden so that application knows how to extract the track 10699e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * id and the informational event type from onInfo callback. 10709e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * 10719e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 10729e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 10739e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_LIST_START = 1000; 10749e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Signal the completion of the track for the recording session. 10759e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 10769e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 10779e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_COMPLETION_STATUS = 1000; 10789e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Indicate the recording progress in time (ms) during recording. 10799e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 10809e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 10819e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_PROGRESS_IN_TIME = 1001; 10829e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Indicate the track type: 0 for Audio and 1 for Video. 10839e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 10849e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 10859e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_TYPE = 1002; 10869e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the track duration information. 10879e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 10889e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 10899e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_DURATION_MS = 1003; 10909e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the max chunk duration in time (ms) for the given track. 10919e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 10929e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 10939e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_MAX_CHUNK_DUR_MS = 1004; 10949e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the total number of recordd frames. 10959e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 10969e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 10979e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_ENCODED_FRAMES = 1005; 10989e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the max spacing between neighboring chunks for the given track. 10999e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11009e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11019e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INTER_CHUNK_TIME_MS = 1006; 11029e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the elapsed time measuring from the start of the recording 11039e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * till the first output frame of the given track is received, excluding 11049e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * any intentional start time offset of a recording session for the 11059e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * purpose of eliminating the recording sound in the recorded file. 11069e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11079e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11089e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_INITIAL_DELAY_MS = 1007; 11099e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the start time difference (delay) betweeen this track and 11109e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * the start of the movie. 11119e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11129e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11139e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_START_OFFSET_MS = 1008; 11140f32fb3ecfdfaa03acf880a356629d43da3fe2feJames Dong /** Provide the total number of data (in kilo-bytes) encoded. 11150f32fb3ecfdfaa03acf880a356629d43da3fe2feJames Dong * {@hide} 11160f32fb3ecfdfaa03acf880a356629d43da3fe2feJames Dong */ 11170f32fb3ecfdfaa03acf880a356629d43da3fe2feJames Dong public static final int MEDIA_RECORDER_TRACK_INFO_DATA_KBYTES = 1009; 11189e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** 11199e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11209e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11219e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_LIST_END = 2000; 11229e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong 11239e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong 1124ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /** 11256f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * Interface definition of a callback to be invoked to communicate some 11266f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * info and/or warning about the recording. 1127ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 1128ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project public interface OnInfoListener 1129ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project { 1130ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /** 11316f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * Called to indicate an info or a warning during recording. 11322bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang * 11336f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * @param mr the MediaRecorder the info pertains to 11346f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * @param what the type of info or warning that has occurred 1135ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * <ul> 1136ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * <li>{@link #MEDIA_RECORDER_INFO_UNKNOWN} 1137105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * <li>{@link #MEDIA_RECORDER_INFO_MAX_DURATION_REACHED} 1138105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * <li>{@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED} 1139ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * </ul> 11406f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * @param extra an extra code, specific to the info type 1141ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 1142ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project void onInfo(MediaRecorder mr, int what, int extra); 1143ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project } 1144ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 1145ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /** 1146ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * Register a callback to be invoked when an informational event occurs while 1147ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * recording. 1148ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * 1149ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * @param listener the callback that will be run 1150ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 1151ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project public void setOnInfoListener(OnInfoListener listener) 1152ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project { 1153ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project mOnInfoListener = listener; 1154ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project } 1155ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 11569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private class EventHandler extends Handler 11579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 11589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private MediaRecorder mMediaRecorder; 11599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 11609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public EventHandler(MediaRecorder mr, Looper looper) { 11619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project super(looper); 11629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mMediaRecorder = mr; 11639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 11649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1165ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /* Do not change these values without updating their counterparts 11669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediarecorder.h! 11679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 11689e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_EVENT_LIST_START = 1; 11699e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_EVENT_ERROR = 1; 11709e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_EVENT_INFO = 2; 11719e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_EVENT_LIST_END = 99; 11729e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong 11739e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /* Events related to individual tracks */ 11749e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_TRACK_EVENT_LIST_START = 100; 11759e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_TRACK_EVENT_ERROR = 100; 11769e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_TRACK_EVENT_INFO = 101; 11779e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_TRACK_EVENT_LIST_END = 1000; 11789e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong 11799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 11809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @Override 11819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void handleMessage(Message msg) { 11829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mMediaRecorder.mNativeContext == 0) { 11839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.w(TAG, "mediarecorder went away with unhandled events"); 11849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 11859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 11869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project switch(msg.what) { 11879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project case MEDIA_RECORDER_EVENT_ERROR: 11889e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong case MEDIA_RECORDER_TRACK_EVENT_ERROR: 11899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mOnErrorListener != null) 11909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnErrorListener.onError(mMediaRecorder, msg.arg1, msg.arg2); 11919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 11929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 11939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1194ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project case MEDIA_RECORDER_EVENT_INFO: 11959e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong case MEDIA_RECORDER_TRACK_EVENT_INFO: 1196ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project if (mOnInfoListener != null) 1197ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project mOnInfoListener.onInfo(mMediaRecorder, msg.arg1, msg.arg2); 1198ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 1199ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project return; 1200ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 12019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project default: 12029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.e(TAG, "Unknown message type " + msg.what); 12039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 12049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 12099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Called from native code when an interesting event happens. This method 12109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * just uses the EventHandler system to post the event back to the main app thread. 12119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * We use a weak reference to the original MediaRecorder object so that the native 12129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * code is safe from the object disappearing from underneath it. (This is 12139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the cookie passed to native_setup().) 12149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 12159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private static void postEventFromNative(Object mediarecorder_ref, 12169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project int what, int arg1, int arg2, Object obj) 12179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 12189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project MediaRecorder mr = (MediaRecorder)((WeakReference)mediarecorder_ref).get(); 12199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mr == null) { 12209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 12219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mr.mEventHandler != null) { 12249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Message m = mr.mEventHandler.obtainMessage(what, arg1, arg2, obj); 12259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mr.mEventHandler.sendMessage(m); 12269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 12309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Releases resources associated with this MediaRecorder object. 12319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * It is good practice to call this method when you're done 123289ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * using the MediaRecorder. In particular, whenever an Activity 123389ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * of an application is paused (its onPause() method is called), 123489ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * or stopped (its onStop() method is called), this method should be 123589ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * invoked to release the MediaRecorder object, unless the application 123689ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * has a special need to keep the object around. In addition to 123789ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * unnecessary resources (such as memory and instances of codecs) 123889ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * being held, failure to call this method immediately if a 123989ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * MediaRecorder object is no longer needed may also lead to 124089ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * continuous battery consumption for mobile devices, and recording 124189ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * failure for other applications if no multiple instances of the 124289ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * same codec are supported on a device. Even if multiple instances 124389ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * of the same codec are supported, some performance degradation 124489ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * may be expected when unnecessary multiple instances are used 124589ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * at the same time. 12469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 12479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void release(); 12489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12494935d05eaa306cef88cf0ab13eca386f270409ecMarco Nelissen private static native final void native_init(); 12504935d05eaa306cef88cf0ab13eca386f270409ecMarco Nelissen 1251788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala private native final void native_setup(Object mediarecorder_this, 1252fa5ecdc4ac6d7a8db2bb9e4a6a60a3189025df30Svet Ganov String clientName, String opPackageName) throws IllegalStateException; 12539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native final void native_finalize(); 12559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12560fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong private native void setParameter(String nameValuePair); 12570fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong 12589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @Override 12599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project protected void finalize() { native_finalize(); } 12609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 1261