MediaRecorder.java revision f2d0e40bf01fa133dd6b36f3716005d53fa9776c
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; 23f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essickimport android.media.MediaMetricsSet; 24b0bd62f96cd81f5209ea01e4f484f5b35a389cc0Ray Essickimport android.os.Bundle; 259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Handler; 269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Looper; 279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.os.Message; 289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.Log; 299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.view.Surface; 3042419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li 319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.io.FileDescriptor; 3242419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Liimport java.io.IOException; 330d5d3b7cc8b9ff142269a947443c758cb2af4684Robert Shihimport java.io.RandomAccessFile; 349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.lang.ref.WeakReference; 359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/** 379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Used to record audio and video. The recording control is based on a 389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * simple state machine (see below). 399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p><img src="{@docRoot}images/mediarecorder_state_diagram.gif" border="0" /> 419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </p> 429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>A common case of using MediaRecorder to record audio works as follows: 449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <pre>MediaRecorder recorder = new MediaRecorder(); 469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.setOutputFile(PATH_NAME); 509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.prepare(); 519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.start(); // Recording is now started 529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * ... 539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.stop(); 549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.reset(); // You can reuse the object by going back to setAudioSource() step 559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.release(); // Now the object cannot be reused 569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </pre> 579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 589ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * <p>Applications may want to register for informational and error 599ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * events in order to be informed of some internal update and possible 609ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * runtime errors during recording. Registration for such events is 619ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * done by setting the appropriate listeners (via calls 629ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * (to {@link #setOnInfoListener(OnInfoListener)}setOnInfoListener and/or 639ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * {@link #setOnErrorListener(OnErrorListener)}setOnErrorListener). 649ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * In order to receive the respective callback associated with these listeners, 659ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * applications are required to create MediaRecorder objects on threads with a 669ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * Looper running (the main UI thread by default already has a Looper running). 679ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * 6861fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <p><strong>Note:</strong> Currently, MediaRecorder does not work on the emulator. 6961fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * 7061fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <div class="special reference"> 7161fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <h3>Developer Guides</h3> 7261fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <p>For more information about how to use MediaRecorder for recording video, read the 7361fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <a href="{@docRoot}guide/topics/media/camera.html#capture-video">Camera</a> developer guide. 7461fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * For more information about how to use MediaRecorder for recording sound, read the 7561fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <a href="{@docRoot}guide/topics/media/audio-capture.html">Audio Capture</a> developer guide.</p> 7661fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * </div> 779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class MediaRecorder 799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{ 809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project static { 819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project System.loadLibrary("media_jni"); 824935d05eaa306cef88cf0ab13eca386f270409ecMarco Nelissen native_init(); 839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private final static String TAG = "MediaRecorder"; 859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // The two fields below are accessed by native methods 879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @SuppressWarnings("unused") 88075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat private long mNativeContext; 899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @SuppressWarnings("unused") 919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private Surface mSurface; 929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private String mPath; 949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private FileDescriptor mFd; 959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private EventHandler mEventHandler; 969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private OnErrorListener mOnErrorListener; 97ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project private OnInfoListener mOnInfoListener; 989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Default constructor. 1019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public MediaRecorder() { 1039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Looper looper; 1059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if ((looper = Looper.myLooper()) != null) { 1069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler = new EventHandler(this, looper); 1079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else if ((looper = Looper.getMainLooper()) != null) { 1089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler = new EventHandler(this, looper); 1099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else { 1109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler = null; 1119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 113788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala String packageName = ActivityThread.currentPackageName(); 1149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Native setup requires a weak reference to our object. 1159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * It's easier to create it here than in C++. 1169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 117fbf0ecabac5d7a929628b43ffe8f4f953e47bd54Svetoslav native_setup(new WeakReference<MediaRecorder>(this), packageName, 118fbf0ecabac5d7a929628b43ffe8f4f953e47bd54Svetoslav ActivityThread.currentOpPackageName()); 1199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 122b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * Sets a {@link android.hardware.Camera} to use for recording. 123b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * 124b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * <p>Use this function to switch quickly between preview and capture mode without a teardown of 125b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * the camera object. {@link android.hardware.Camera#unlock()} should be called before 126b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * this. Must call before {@link #prepare}.</p> 1279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param c the Camera to use for recording 129b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * @deprecated Use {@link #getSurface} and the {@link android.hardware.camera2} API instead. 1309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 131b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala @Deprecated 1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setCamera(Camera c); 1339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 13583cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * Gets the surface to record from when using SURFACE video source. 136b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * 137b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * <p> May only be called after {@link #prepare}. Frames rendered to the Surface before 138b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * {@link #start} will be discarded.</p> 139b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * 140b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * @throws IllegalStateException if it is called before {@link #prepare}, after 141b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * {@link #stop}, or is called when VideoSource is not set to SURFACE. 14283cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * @see android.media.MediaRecorder.VideoSource 14383cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang */ 14483cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang public native Surface getSurface(); 14583cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang 14683cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang /** 14717d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * Configures the recorder to use a persistent surface when using SURFACE video source. 14803359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang * <p> May only be called before {@link #prepare}. If called, {@link #getSurface} should 14903359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang * not be used and will throw IllegalStateException. Frames rendered to the Surface 15003359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang * before {@link #start} will be discarded.</p> 15117d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar 15217d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * @param surface a persistent input surface created by 15317d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * {@link MediaCodec#createPersistentInputSurface} 15403359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang * @throws IllegalStateException if it is called after {@link #prepare} and before 15503359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang * {@link #stop}. 15617d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * @throws IllegalArgumentException if the surface was not created by 15717d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * {@link MediaCodec#createPersistentInputSurface}. 15817d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * @see MediaCodec#createPersistentInputSurface 15917d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * @see MediaRecorder.VideoSource 16017d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar */ 1619560ddb48af0e2da7743452f8d9d6d9cd34d8438Chong Zhang public void setInputSurface(@NonNull Surface surface) { 16203359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang if (!(surface instanceof MediaCodec.PersistentSurface)) { 16303359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang throw new IllegalArgumentException("not a PersistentSurface"); 16403359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang } 1659560ddb48af0e2da7743452f8d9d6d9cd34d8438Chong Zhang native_setInputSurface(surface); 16617d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar } 16717d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar 1689560ddb48af0e2da7743452f8d9d6d9cd34d8438Chong Zhang private native final void native_setInputSurface(@NonNull Surface surface); 16903359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang 17017d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar /** 1719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets a Surface to show a preview of recorded media (video). Calls this 1729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * before prepare() to make sure that the desirable preview display is 173c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * set. If {@link #setCamera(Camera)} is used and the surface has been 174c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * already set to the camera, application do not need to call this. If 175c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * this is called with non-null surface, the preview surface of the camera 176c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * will be replaced by the new surface. If this method is called with null 177c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * surface or not called at all, media recorder will not change the preview 178c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * surface of the camera. 1799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param sv the Surface to use for the preview 181c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * @see android.hardware.Camera#setPreviewDisplay(android.view.SurfaceHolder) 1829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setPreviewDisplay(Surface sv) { 1849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mSurface = sv; 1859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1887af0d66c2270d2b804b029bf33d6d8b532625a74Jean-Michel Trivi * Defines the audio source. 1897af0d66c2270d2b804b029bf33d6d8b532625a74Jean-Michel Trivi * An audio source defines both a default physical source of audio signal, and a recording 190fd3ac3da172b877c6f316de2d066883e7a2d0631Jean-Michel Trivi * configuration. These constants are for instance used 1917af0d66c2270d2b804b029bf33d6d8b532625a74Jean-Michel Trivi * in {@link MediaRecorder#setAudioSource(int)} or 192fd3ac3da172b877c6f316de2d066883e7a2d0631Jean-Michel Trivi * {@link AudioRecord.Builder#setAudioSource(int)}. 1939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final class AudioSource { 195701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi 196701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi private AudioSource() {} 197701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi 198701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi /** @hide */ 199701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi public final static int AUDIO_SOURCE_INVALID = -1; 200701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi 2019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 202b2b292317482d00d067bc91669322b273be61926Rom Lemarchand * in system/media/audio/include/system/audio.h! 2039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2040f0fbd9441f40c6f99470b89774e397f99bf61ebGlenn Kasten 2050f0fbd9441f40c6f99470b89774e397f99bf61ebGlenn Kasten /** Default audio source **/ 2069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT = 0; 2070f0fbd9441f40c6f99470b89774e397f99bf61ebGlenn Kasten 2089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** Microphone audio source */ 2099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int MIC = 1; 2104bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent 211851a8797bd6db96152a7867f4a52b146e25641feEric Laurent /** Voice call uplink (Tx) audio source. 212851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * <p> 213851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * Capturing from <code>VOICE_UPLINK</code> source requires the 214851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * {@link android.Manifest.permission#CAPTURE_AUDIO_OUTPUT} permission. 215851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * This permission is reserved for use by system components and is not available to 216851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * third-party applications. 217851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * </p> 218851a8797bd6db96152a7867f4a52b146e25641feEric Laurent */ 2194bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent public static final int VOICE_UPLINK = 2; 2204bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent 221851a8797bd6db96152a7867f4a52b146e25641feEric Laurent /** Voice call downlink (Rx) audio source. 222851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * <p> 223851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * Capturing from <code>VOICE_DOWNLINK</code> source requires the 224851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * {@link android.Manifest.permission#CAPTURE_AUDIO_OUTPUT} permission. 225851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * This permission is reserved for use by system components and is not available to 226851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * third-party applications. 227851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * </p> 228851a8797bd6db96152a7867f4a52b146e25641feEric Laurent */ 2294bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent public static final int VOICE_DOWNLINK = 3; 2304bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent 231851a8797bd6db96152a7867f4a52b146e25641feEric Laurent /** Voice call uplink + downlink audio source 232851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * <p> 233851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * Capturing from <code>VOICE_CALL</code> source requires the 234851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * {@link android.Manifest.permission#CAPTURE_AUDIO_OUTPUT} permission. 235851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * This permission is reserved for use by system components and is not available to 236851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * third-party applications. 237851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * </p> 238851a8797bd6db96152a7867f4a52b146e25641feEric Laurent */ 2394bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent public static final int VOICE_CALL = 4; 2406869df3a5db0ca0037394f0fd14aecc1d80b5b42Jean-Michel Trivi 2415d1828ee401156cede1d65257d59d66be281edd3Jean-Michel Trivi /** Microphone audio source tuned for video recording, with the same orientation 2425d1828ee401156cede1d65257d59d66be281edd3Jean-Michel Trivi * as the camera if available. */ 2436869df3a5db0ca0037394f0fd14aecc1d80b5b42Jean-Michel Trivi public static final int CAMCORDER = 5; 2446869df3a5db0ca0037394f0fd14aecc1d80b5b42Jean-Michel Trivi 2455d1828ee401156cede1d65257d59d66be281edd3Jean-Michel Trivi /** Microphone audio source tuned for voice recognition. */ 2466869df3a5db0ca0037394f0fd14aecc1d80b5b42Jean-Michel Trivi public static final int VOICE_RECOGNITION = 6; 247820b9e0d3b6f94fe0b524aebf756ce25df273e6aJean-Michel Trivi 248ffd0eb0f1106b0229694a1a86ce7d6356efcf50dJean-Michel Trivi /** Microphone audio source tuned for voice communications such as VoIP. It 249ffd0eb0f1106b0229694a1a86ce7d6356efcf50dJean-Michel Trivi * will for instance take advantage of echo cancellation or automatic gain control 2505d1828ee401156cede1d65257d59d66be281edd3Jean-Michel Trivi * if available. 251820b9e0d3b6f94fe0b524aebf756ce25df273e6aJean-Michel Trivi */ 252820b9e0d3b6f94fe0b524aebf756ce25df273e6aJean-Michel Trivi public static final int VOICE_COMMUNICATION = 7; 25364dfb604e70b70b7c346768114e05ddfadc09addJeff Brown 25464dfb604e70b70b7c346768114e05ddfadc09addJeff Brown /** 25564dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * Audio source for a submix of audio streams to be presented remotely. 25664dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * <p> 25764dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * An application can use this audio source to capture a mix of audio streams 25864dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * that should be transmitted to a remote receiver such as a Wifi display. 25964dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * While recording is active, these audio streams are redirected to the remote 26064dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * submix instead of being played on the device speaker or headset. 26164dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * </p><p> 26264dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * Certain streams are excluded from the remote submix, including 26364dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * {@link AudioManager#STREAM_RING}, {@link AudioManager#STREAM_ALARM}, 26464dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * and {@link AudioManager#STREAM_NOTIFICATION}. These streams will continue 26564dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * to be presented locally as usual. 26664dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * </p><p> 26764dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * Capturing the remote submix audio requires the 26864dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * {@link android.Manifest.permission#CAPTURE_AUDIO_OUTPUT} permission. 26964dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * This permission is reserved for use by system components and is not available to 27064dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * third-party applications. 27164dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * </p> 27264dfb604e70b70b7c346768114e05ddfadc09addJeff Brown */ 27364dfb604e70b70b7c346768114e05ddfadc09addJeff Brown public static final int REMOTE_SUBMIX = 8; 274357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent 275a7cc59c3187711d390c5a483d26c463a1bcbd331rago /** Microphone audio source tuned for unprocessed (raw) sound if available, behaves like 276a7cc59c3187711d390c5a483d26c463a1bcbd331rago * {@link #DEFAULT} otherwise. */ 277a7cc59c3187711d390c5a483d26c463a1bcbd331rago public static final int UNPROCESSED = 9; 278a7cc59c3187711d390c5a483d26c463a1bcbd331rago 279357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent /** 28000a009204e51997249d60eab4f147eff566e2b1fEric Laurent * Audio source for capturing broadcast radio tuner output. 281ce4483cb83afb3a42a32ef2cb00cf04d6f9018fdBenson Huang * @hide 282ce4483cb83afb3a42a32ef2cb00cf04d6f9018fdBenson Huang */ 28300a009204e51997249d60eab4f147eff566e2b1fEric Laurent @SystemApi 28400a009204e51997249d60eab4f147eff566e2b1fEric Laurent public static final int RADIO_TUNER = 1998; 285ce4483cb83afb3a42a32ef2cb00cf04d6f9018fdBenson Huang 286ce4483cb83afb3a42a32ef2cb00cf04d6f9018fdBenson Huang /** 287357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * Audio source for preemptible, low-priority software hotword detection 288357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * It presents the same gain and pre processing tuning as {@link #VOICE_RECOGNITION}. 289357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * <p> 290357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * An application should use this audio source when it wishes to do 291357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * always-on software hotword detection, while gracefully giving in to any other application 292357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * that might want to read from the microphone. 293357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * </p> 294357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * This is a hidden audio source. 295357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * @hide 296357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent */ 29700a009204e51997249d60eab4f147eff566e2b1fEric Laurent @SystemApi 29800a009204e51997249d60eab4f147eff566e2b1fEric Laurent public static final int HOTWORD = 1999; 2999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 301dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi // TODO make AudioSource static (API change) and move this method inside the AudioSource class 302dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi /** 303dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi * @hide 304dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi * @param source An audio source to test 305dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi * @return true if the source is only visible to system components 306dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi */ 307dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi public static boolean isSystemOnlyAudioSource(int source) { 308dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi switch(source) { 309dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.DEFAULT: 310dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.MIC: 311dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.VOICE_UPLINK: 312dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.VOICE_DOWNLINK: 313dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.VOICE_CALL: 314dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.CAMCORDER: 315dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.VOICE_RECOGNITION: 316dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.VOICE_COMMUNICATION: 317dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi //case REMOTE_SUBMIX: considered "system" as it requires system permissions 318dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.UNPROCESSED: 319dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi return false; 320dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi default: 321dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi return true; 322dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi } 323dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi } 324dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi 3259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Defines the video source. These constants are used with 3279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link MediaRecorder#setVideoSource(int)}. 3289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final class VideoSource { 3309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 3319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediarecorder.h! 3329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private VideoSource() {} 3349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT = 0; 33583cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang /** Camera video source 33683cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * <p> 337b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * Using the {@link android.hardware.Camera} API as video source. 33883cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * </p> 33983cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang */ 3409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int CAMERA = 1; 34183cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang /** Surface video source 34283cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * <p> 34383cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * Using a Surface as video source. 34483cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * </p><p> 34583cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * This flag must be used when recording from an 346b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * {@link android.hardware.camera2} API source. 34783cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * </p><p> 34883cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * When using this video source type, use {@link MediaRecorder#getSurface()} 34983cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * to retrieve the surface created by MediaRecorder. 35083cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang */ 35183cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang public static final int SURFACE = 2; 3529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Defines the output format. These constants are used with 3569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link MediaRecorder#setOutputFormat(int)}. 3579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final class OutputFormat { 3599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 3609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediarecorder.h! 3619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private OutputFormat() {} 3639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT = 0; 3649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3GPP media file format*/ 3659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int THREE_GPP = 1; 3669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** MPEG4 media file format*/ 3679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int MPEG_4 = 2; 3682bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang 369874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong /** The following formats are audio only .aac or .amr formats */ 370874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong 371874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong /** 372874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong * AMR NB file format 373874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong * @deprecated Deprecated in favor of MediaRecorder.OutputFormat.AMR_NB 374874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong */ 3759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int RAW_AMR = 3; 376874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong 3772116dc91e96f7153f65468ed40a0b57e437679f7James Dong /** AMR NB file format */ 3782bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AMR_NB = 3; 379874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong 3802116dc91e96f7153f65468ed40a0b57e437679f7James Dong /** AMR WB file format */ 3812bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AMR_WB = 4; 382874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong 3832bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang /** @hide AAC ADIF file format */ 3842bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AAC_ADIF = 5; 385874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong 386874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong /** AAC ADTS file format */ 3872bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AAC_ADTS = 6; 38857648e4eec7dd2593af467877bc7cce4aa654759Andreas Huber 38957648e4eec7dd2593af467877bc7cce4aa654759Andreas Huber /** @hide Stream over a socket, limited to a single stream */ 39057648e4eec7dd2593af467877bc7cce4aa654759Andreas Huber public static final int OUTPUT_FORMAT_RTP_AVP = 7; 3919adf466021d37a5062d7d3361e14bfd9e7ffeba6Andreas Huber 3925b168a0c549a164898b5f1568b155d02ccce77cdHangyu Kuang /** H.264/AAC data encapsulated in MPEG2/TS */ 3935b168a0c549a164898b5f1568b155d02ccce77cdHangyu Kuang public static final int MPEG_2_TS = 8; 394c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih 395c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih /** VP8/VORBIS data in a WEBM container */ 396c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih public static final int WEBM = 9; 3979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project }; 3989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Defines the audio encoding. These constants are used with 4019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link MediaRecorder#setAudioEncoder(int)}. 4029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final class AudioEncoder { 4049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 4059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediarecorder.h! 4069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private AudioEncoder() {} 4089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT = 0; 4099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** AMR (Narrowband) audio codec */ 4109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AMR_NB = 1; 4112116dc91e96f7153f65468ed40a0b57e437679f7James Dong /** AMR (Wideband) audio codec */ 4122bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AMR_WB = 2; 413ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke /** AAC Low Complexity (AAC-LC) audio codec */ 4142bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AAC = 3; 415ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke /** High Efficiency AAC (HE-AAC) audio codec */ 416ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke public static final int HE_AAC = 4; 417ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke /** Enhanced Low Delay AAC (AAC-ELD) audio codec */ 418ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke public static final int AAC_ELD = 5; 419c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih /** Ogg Vorbis audio codec */ 420c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih public static final int VORBIS = 6; 4219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Defines the video encoding. These constants are used with 4259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link MediaRecorder#setVideoEncoder(int)}. 4269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final class VideoEncoder { 4289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 4299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediarecorder.h! 4309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private VideoEncoder() {} 4329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT = 0; 4339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int H263 = 1; 4349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int H264 = 2; 4359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int MPEG_4_SP = 3; 436c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih public static final int VP8 = 4; 437886e562bc5aa51b1bbb3f429a440d1f4e90db1c2Wonsik Kim public static final int HEVC = 5; 4389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the audio source to be used for recording. If this method is not 4429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * called, the output file will not contain an audio track. The source needs 4439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to be specified before setting recording-parameters or encoders. Call 4449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this only before setOutputFormat(). 4459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 4469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param audio_source the audio source to use 4479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after setOutputFormat() 4489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.AudioSource 4499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setAudioSource(int audio_source) 4519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 4529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4544bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent * Gets the maximum value for audio sources. 4554bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent * @see android.media.MediaRecorder.AudioSource 4564bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent */ 4572ac2afeac989ea1dc326b0db996d6c6c8e00cc29Jean-Michel Trivi public static final int getAudioSourceMax() { 458a7cc59c3187711d390c5a483d26c463a1bcbd331rago return AudioSource.UNPROCESSED; 4592ac2afeac989ea1dc326b0db996d6c6c8e00cc29Jean-Michel Trivi } 4604bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent 4614bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent /** 4629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the video source to be used for recording. If this method is not 4639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * called, the output file will not contain an video track. The source needs 4649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to be specified before setting recording-parameters or encoders. Call 4659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this only before setOutputFormat(). 4669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 4679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param video_source the video source to use 4689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after setOutputFormat() 4699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.VideoSource 4709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setVideoSource(int video_source) 4729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 4739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 475e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong * Uses the settings from a CamcorderProfile object for recording. This method should 476e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong * be called after the video AND audio sources are set, and before setOutputFile(). 477a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * If a time lapse CamcorderProfile is used, audio related source or recording 478a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * parameters are ignored. 479e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong * 480e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong * @param profile the CamcorderProfile to use 481e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong * @see android.media.CamcorderProfile 482e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong */ 483e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong public void setProfile(CamcorderProfile profile) { 484e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong setOutputFormat(profile.fileFormat); 485e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong setVideoFrameRate(profile.videoFrameRate); 486e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight); 487e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong setVideoEncodingBitRate(profile.videoBitRate); 488e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong setVideoEncoder(profile.videoCodec); 4894f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra if (profile.quality >= CamcorderProfile.QUALITY_TIME_LAPSE_LOW && 49033fe290ca33235d7e0988cace14de3319a9a83f1James Dong profile.quality <= CamcorderProfile.QUALITY_TIME_LAPSE_QVGA) { 491a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong // Nothing needs to be done. Call to setCaptureRate() enables 492a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong // time lapse video recording. 4934f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra } else { 4944f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra setAudioEncodingBitRate(profile.audioBitRate); 4954f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra setAudioChannels(profile.audioChannels); 4964f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra setAudioSamplingRate(profile.audioSampleRate); 4974f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra setAudioEncoder(profile.audioCodec); 4984f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra } 499e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong } 500e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong 501e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong /** 5024f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * Set video frame capture rate. This can be used to set a different video frame capture 503a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * rate than the recorded video's playback rate. This method also sets the recording mode 504a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * to time lapse. In time lapse video recording, only video is recorded. Audio related 505a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * parameters are ignored when a time lapse recording session starts, if an application 506a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * sets them. 507ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra * 5084f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * @param fps Rate at which frames should be captured in frames per second. 5094f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * The fps can go as low as desired. However the fastest fps will be limited by the hardware. 5104f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * For resolutions that can be captured by the video camera, the fastest fps can be computed using 5114f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * {@link android.hardware.Camera.Parameters#getPreviewFpsRange(int[])}. For higher 5124f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * resolutions the fastest fps may be more restrictive. 5134f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * Note that the recorder cannot guarantee that frames will be captured at the 5144f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * given rate due to camera/encoder limitations. However it tries to be as close as 5154f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * possible. 516ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra */ 5174f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra public void setCaptureRate(double fps) { 518a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong // Make sure that time lapse is enabled when this method is called. 5191c7928e8c68654d087f83c7cefc59095950b8befJohan Redestig setParameter("time-lapse-enable=1"); 520fbdee2c04b88210bab5c9a769908be42d1775e16Chong Zhang setParameter("time-lapse-fps=" + fps); 521ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra } 522ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra 523ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra /** 524ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * Sets the orientation hint for output video playback. 5255aa95dd36cd0708d25accd8d745ae8ebc255758fJames Dong * This method should be called before prepare(). This method will not 526ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * trigger the source video frame to rotate during video recording, but to 527ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * add a composition matrix containing the rotation angle in the output 528ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * video if the output format is OutputFormat.THREE_GPP or 529ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * OutputFormat.MPEG_4 so that a video player can choose the proper 530ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * orientation for playback. Note that some video players may choose 531ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * to ignore the compostion matrix in a video during playback. 532ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * 533ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * @param degrees the angle to be rotated clockwise in degrees. 534ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * The supported angles are 0, 90, 180, and 270 degrees. 535ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * @throws IllegalArgumentException if the angle is not supported. 536ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * 537ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong */ 538ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong public void setOrientationHint(int degrees) { 539ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong if (degrees != 0 && 540ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong degrees != 90 && 541ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong degrees != 180 && 542ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong degrees != 270) { 543ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong throw new IllegalArgumentException("Unsupported angle: " + degrees); 544ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong } 5452450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund setParameter("video-param-rotation-angle-degrees=" + degrees); 546ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong } 547ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong 548ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong /** 549af3131fe2e20c7b5e080d098a3b6847c5414bcaeJames Dong * Set and store the geodata (latitude and longitude) in the output file. 550987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * This method should be called before prepare(). The geodata is 551987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * stored in udta box if the output format is OutputFormat.THREE_GPP 552987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * or OutputFormat.MPEG_4, and is ignored for other output formats. 553987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * The geodata is stored according to ISO-6709 standard. 554987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * 555987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * @param latitude latitude in degrees. Its value must be in the 556987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * range [-90, 90]. 557987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * @param longitude longitude in degrees. Its value must be in the 558987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * range [-180, 180]. 559987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * 560987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * @throws IllegalArgumentException if the given latitude or 561987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * longitude is out of range. 562987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * 563987ab4833ecbafbdf750eb1b04e43693433c4783James Dong */ 564af3131fe2e20c7b5e080d098a3b6847c5414bcaeJames Dong public void setLocation(float latitude, float longitude) { 565987ab4833ecbafbdf750eb1b04e43693433c4783James Dong int latitudex10000 = (int) (latitude * 10000 + 0.5); 566987ab4833ecbafbdf750eb1b04e43693433c4783James Dong int longitudex10000 = (int) (longitude * 10000 + 0.5); 567987ab4833ecbafbdf750eb1b04e43693433c4783James Dong 568987ab4833ecbafbdf750eb1b04e43693433c4783James Dong if (latitudex10000 > 900000 || latitudex10000 < -900000) { 569af3131fe2e20c7b5e080d098a3b6847c5414bcaeJames Dong String msg = "Latitude: " + latitude + " out of range."; 570987ab4833ecbafbdf750eb1b04e43693433c4783James Dong throw new IllegalArgumentException(msg); 571987ab4833ecbafbdf750eb1b04e43693433c4783James Dong } 572987ab4833ecbafbdf750eb1b04e43693433c4783James Dong if (longitudex10000 > 1800000 || longitudex10000 < -1800000) { 573af3131fe2e20c7b5e080d098a3b6847c5414bcaeJames Dong String msg = "Longitude: " + longitude + " out of range"; 574987ab4833ecbafbdf750eb1b04e43693433c4783James Dong throw new IllegalArgumentException(msg); 575987ab4833ecbafbdf750eb1b04e43693433c4783James Dong } 576987ab4833ecbafbdf750eb1b04e43693433c4783James Dong 577987ab4833ecbafbdf750eb1b04e43693433c4783James Dong setParameter("param-geotag-latitude=" + latitudex10000); 578987ab4833ecbafbdf750eb1b04e43693433c4783James Dong setParameter("param-geotag-longitude=" + longitudex10000); 579987ab4833ecbafbdf750eb1b04e43693433c4783James Dong } 580987ab4833ecbafbdf750eb1b04e43693433c4783James Dong 581987ab4833ecbafbdf750eb1b04e43693433c4783James Dong /** 5829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the format of the output file produced during recording. Call this 5839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * after setAudioSource()/setVideoSource() but before prepare(). 5849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 5852170312ab0b6766e8b73b806efbe6abdbb702bbcDave Sparks * <p>It is recommended to always use 3GP format when using the H.263 5862170312ab0b6766e8b73b806efbe6abdbb702bbcDave Sparks * video encoder and AMR audio encoder. Using an MPEG-4 container format 5872170312ab0b6766e8b73b806efbe6abdbb702bbcDave Sparks * may confuse some desktop players.</p> 5882170312ab0b6766e8b73b806efbe6abdbb702bbcDave Sparks * 5899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param output_format the output format to use. The output format 5909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * needs to be specified before setting recording-parameters or encoders. 5919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after prepare() or before 5929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setAudioSource()/setVideoSource(). 5939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.OutputFormat 5949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setOutputFormat(int output_format) 5969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 5979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the width and height of the video to be captured. Must be called 6009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * after setVideoSource(). Call this after setOutFormat() but before 6019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * prepare(). 6029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param width the width of the video to be captured 6049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param height the height of the video to be captured 6059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after 6069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * prepare() or before setOutputFormat() 6079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setVideoSize(int width, int height) 6099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 6109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the frame rate of the video to be captured. Must be called 6139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * after setVideoSource(). Call this after setOutFormat() but before 6149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * prepare(). 6159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param rate the number of frames per second of video to capture 6179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after 6189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * prepare() or before setOutputFormat(). 6199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * NOTE: On some devices that have auto-frame rate, this sets the 6219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * maximum frame rate, not a constant frame rate. Actual frame rate 6229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * will vary according to lighting conditions. 6239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setVideoFrameRate(int rate) throws IllegalStateException; 6259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 627ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * Sets the maximum duration (in ms) of the recording session. 628ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * Call this after setOutFormat() but before prepare(). 629105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * After recording reaches the specified duration, a notification 630105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * will be sent to the {@link android.media.MediaRecorder.OnInfoListener} 631105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * with a "what" code of {@link #MEDIA_RECORDER_INFO_MAX_DURATION_REACHED} 632105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * and recording will be stopped. Stopping happens asynchronously, there 633105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * is no guarantee that the recorder will have stopped by the time the 634105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * listener is notified. 635ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * 636ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * @param max_duration_ms the maximum duration in ms (if zero or negative, disables the duration limit) 637ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * 638ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 639ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project public native void setMaxDuration(int max_duration_ms) throws IllegalArgumentException; 640ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 641ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /** 642105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * Sets the maximum filesize (in bytes) of the recording session. 643105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * Call this after setOutFormat() but before prepare(). 644105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * After recording reaches the specified filesize, a notification 645105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * will be sent to the {@link android.media.MediaRecorder.OnInfoListener} 646105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * with a "what" code of {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED} 647105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * and recording will be stopped. Stopping happens asynchronously, there 648105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * is no guarantee that the recorder will have stopped by the time the 649105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * listener is notified. 650105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * 651105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * @param max_filesize_bytes the maximum filesize in bytes (if zero or negative, disables the limit) 652105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * 653105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project */ 654105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project public native void setMaxFileSize(long max_filesize_bytes) throws IllegalArgumentException; 655105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project 656105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project /** 6579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the audio encoder to be used for recording. If this method is not 6589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * called, the output file will not contain an audio track. Call this after 6599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() but before prepare(). 6609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param audio_encoder the audio encoder to use. 6629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 6639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() or after prepare(). 6649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.AudioEncoder 6659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setAudioEncoder(int audio_encoder) 6679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 6689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the video encoder to be used for recording. If this method is not 6719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * called, the output file will not contain an video track. Call this after 6729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() and before prepare(). 6739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param video_encoder the video encoder to use. 6759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 6769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() or after prepare() 6779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.VideoEncoder 6789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setVideoEncoder(int video_encoder) 6809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 6819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6830fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Sets the audio sampling rate for recording. Call this method before prepare(). 6840fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Prepare() may perform additional checks on the parameter to make sure whether 6850fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * the specified audio sampling rate is applicable. The sampling rate really depends 6860fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * on the format for the audio recording, as well as the capabilities of the platform. 6870fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * For instance, the sampling rate supported by AAC audio coding standard ranges 68854815a78aff9bd453a8f0ac3c02f3a35c4b04146James Dong * from 8 to 96 kHz, the sampling rate supported by AMRNB is 8kHz, and the sampling 68954815a78aff9bd453a8f0ac3c02f3a35c4b04146James Dong * rate supported by AMRWB is 16kHz. Please consult with the related audio coding 69054815a78aff9bd453a8f0ac3c02f3a35c4b04146James Dong * standard for the supported audio sampling rate. 6910fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * 6920fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * @param samplingRate the sampling rate for audio in samples per second. 6930fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong */ 6940fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong public void setAudioSamplingRate(int samplingRate) { 6950fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong if (samplingRate <= 0) { 6960fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong throw new IllegalArgumentException("Audio sampling rate is not positive"); 6970fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 6982450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund setParameter("audio-param-sampling-rate=" + samplingRate); 6990fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7000fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong 7010fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong /** 7020fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Sets the number of audio channels for recording. Call this method before prepare(). 7030fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Prepare() may perform additional checks on the parameter to make sure whether the 7040fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * specified number of audio channels are applicable. 7052bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang * 7060fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * @param numChannels the number of audio channels. Usually it is either 1 (mono) or 2 7070fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * (stereo). 7082bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang */ 7090fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong public void setAudioChannels(int numChannels) { 7100fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong if (numChannels <= 0) { 7110fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong throw new IllegalArgumentException("Number of channels is not positive"); 7120fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7132450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund setParameter("audio-param-number-of-channels=" + numChannels); 7140fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7150fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong 7160fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong /** 7170fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Sets the audio encoding bit rate for recording. Call this method before prepare(). 7180fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Prepare() may perform additional checks on the parameter to make sure whether the 7190fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * specified bit rate is applicable, and sometimes the passed bitRate will be clipped 7200fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * internally to ensure the audio recording can proceed smoothly based on the 7210fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * capabilities of the platform. 7220fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * 7230fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * @param bitRate the audio encoding bit rate in bits per second. 7240fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong */ 7250fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong public void setAudioEncodingBitRate(int bitRate) { 7260fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong if (bitRate <= 0) { 7270fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong throw new IllegalArgumentException("Audio encoding bit rate is not positive"); 7280fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7292450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund setParameter("audio-param-encoding-bitrate=" + bitRate); 7300fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7310fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong 7320fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong /** 7330fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Sets the video encoding bit rate for recording. Call this method before prepare(). 7340fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Prepare() may perform additional checks on the parameter to make sure whether the 7350fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * specified bit rate is applicable, and sometimes the passed bitRate will be 7360fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * clipped internally to ensure the video recording can proceed smoothly based on 7370fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * the capabilities of the platform. 7380fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * 7390fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * @param bitRate the video encoding bit rate in bits per second. 7400fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong */ 7410fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong public void setVideoEncodingBitRate(int bitRate) { 7420fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong if (bitRate <= 0) { 7430fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong throw new IllegalArgumentException("Video encoding bit rate is not positive"); 7440fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7452450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund setParameter("video-param-encoding-bitrate=" + bitRate); 7460fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7472bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang 7482bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang /** 749f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * Sets the video encoding profile for recording. Call this method before prepare(). 750f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * Prepare() may perform additional checks on the parameter to make sure whether the 751f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * specified profile and level are applicable, and sometimes the passed profile or 752f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * level will be discarded due to codec capablity or to ensure the video recording 753f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * can proceed smoothly based on the capabilities of the platform. 754f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * @hide 755f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * @param profile declared in {@link MediaCodecInfo.CodecProfileLevel}. 756f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * @param level declared in {@link MediaCodecInfo.CodecProfileLevel}. 757f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang */ 758f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang public void setVideoEncodingProfileLevel(int profile, int level) { 759f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang if (profile <= 0) { 760f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang throw new IllegalArgumentException("Video encoding profile is not positive"); 761f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang } 762f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang if (level <= 0) { 763f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang throw new IllegalArgumentException("Video encoding level is not positive"); 764f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang } 765f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang setParameter("video-param-encoder-profile=" + profile); 766f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang setParameter("video-param-encoder-level=" + level); 767f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang } 768f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang 769f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang /** 7703ff98beeafd271a65c1f824699431366882b04f6James Dong * Currently not implemented. It does nothing. 7713ff98beeafd271a65c1f824699431366882b04f6James Dong * @deprecated Time lapse mode video recording using camera still image capture 7723ff98beeafd271a65c1f824699431366882b04f6James Dong * is not desirable, and will not be supported. 773029d7e15f38cdd3c1941a16186c5941edc85bc3dJames Dong * @hide 774b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra */ 7751fec21be65ddda46fe39c40e00d2fb94a8ce59f1Nipun Kwatra public void setAuxiliaryOutputFile(FileDescriptor fd) 776b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra { 7773ff98beeafd271a65c1f824699431366882b04f6James Dong Log.w(TAG, "setAuxiliaryOutputFile(FileDescriptor) is no longer supported."); 778b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra } 779b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra 780b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra /** 7813ff98beeafd271a65c1f824699431366882b04f6James Dong * Currently not implemented. It does nothing. 7823ff98beeafd271a65c1f824699431366882b04f6James Dong * @deprecated Time lapse mode video recording using camera still image capture 7833ff98beeafd271a65c1f824699431366882b04f6James Dong * is not desirable, and will not be supported. 784029d7e15f38cdd3c1941a16186c5941edc85bc3dJames Dong * @hide 785b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra */ 7861fec21be65ddda46fe39c40e00d2fb94a8ce59f1Nipun Kwatra public void setAuxiliaryOutputFile(String path) 787b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra { 7883ff98beeafd271a65c1f824699431366882b04f6James Dong Log.w(TAG, "setAuxiliaryOutputFile(String) is no longer supported."); 789b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra } 790b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra 791b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra /** 7929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Pass in the file descriptor of the file to be written. Call this after 7939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() but before prepare(). 7949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 7959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param fd an open file descriptor to be written into. 7969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 7979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() or after prepare() 7989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 7999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setOutputFile(FileDescriptor fd) throws IllegalStateException 8009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 8019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mPath = null; 8029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mFd = fd; 8039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 8059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 806e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * Sets the next output file descriptor to be used when the maximum filesize is reached 807e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * on the prior output {@link #setOutputFile} or {@link #setNextOutputFile}). File descriptor 80882d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * must be seekable and writable. After setting the next output file, application should not 80982d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * use the file referenced by this file descriptor until {@link #stop}. It is the application's 81082d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * responsibility to close the file descriptor. It is safe to do so as soon as this call returns. 81182d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * Application must call this after receiving on the 81282d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * {@link android.media.MediaRecorder.OnInfoListener} a "what" code of 81382d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING} and before receiving a "what" code of 81482d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED}. The file is not used until switching to 81582d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * that output. Application will receive{@link #MEDIA_RECORDER_INFO_NEXT_OUTPUT_FILE_STARTED} 81682d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * when the next output file is used. Application will not be able to set a new output file if 81782d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * the previous one has not been used. Application is responsible for cleaning up unused files 81882d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * after {@link #stop} is called. 819e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * 820e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @param fd an open file descriptor to be written into. 821e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @throws IllegalStateException if it is called before prepare(). 822e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @throws IOException if setNextOutputFile fails otherwise. 823e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang */ 824e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang public void setNextOutputFile(FileDescriptor fd) throws IllegalStateException, IOException 825e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang { 826e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang _setNextOutputFile(fd); 827e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang } 828e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang 829e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang /** 8309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the path of the output file to be produced. Call this after 8319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() but before prepare(). 8329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 8339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param path The pathname to use. 8349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 8359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() or after prepare() 8369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 8379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setOutputFile(String path) throws IllegalStateException 8389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 8399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mFd = null; 8409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mPath = path; 8419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 843e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang /** 844e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * Sets the next output file path to be used when the maximum filesize is reached 845e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * on the prior output {@link #setOutputFile} or {@link #setNextOutputFile}). File should 846e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * be seekable. After setting the next output file, application should not use the file 847e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * referenced by this file descriptor until {@link #stop}. Application must call this 848e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * after receiving on the {@link android.media.MediaRecorder.OnInfoListener} a "what" code of 849e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING} and before receiving a "what" code of 850e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED}. The file is not used until switching to 851e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * that output. Application will receive {@link #MEDIA_RECORDER_INFO_NEXT_OUTPUT_FILE_STARTED} 852e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * when the next output file is used. Application will not be able to set a new output file if 853e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * the previous one has not been used. Application is responsible for cleaning up unused files 854e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * after {@link #stop} is called. 855e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * 856e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @param path The pathname to use. 857e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @throws IllegalStateException if it is called before prepare(). 858e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @throws IOException if setNextOutputFile fails otherwise. 859e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang */ 860e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang public void setNextOutputFile(String path) throws IllegalStateException, IOException 861e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang { 862e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang if (path != null) { 863e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang RandomAccessFile file = new RandomAccessFile(path, "rws"); 864e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang try { 865e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang _setNextOutputFile(file.getFD()); 866e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang } finally { 867e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang file.close(); 868e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang } 869e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang } 870e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang } 871e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang 8729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // native implementation 873e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang private native void _setOutputFile(FileDescriptor fd) throws IllegalStateException, IOException; 874e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang private native void _setNextOutputFile(FileDescriptor fd) throws IllegalStateException, IOException; 8759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native void _prepare() throws IllegalStateException, IOException; 8769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 8779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 8789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Prepares the recorder to begin capturing and encoding data. This method 8799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * must be called after setting up the desired audio and video sources, 8809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * encoders, file format, etc., but before start(). 8819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 8829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after 8839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * start() or before setOutputFormat(). 8849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IOException if prepare fails otherwise. 8859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 8869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void prepare() throws IllegalStateException, IOException 8879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 8889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mPath != null) { 8890d5d3b7cc8b9ff142269a947443c758cb2af4684Robert Shih RandomAccessFile file = new RandomAccessFile(mPath, "rws"); 8909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 891e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang _setOutputFile(file.getFD()); 8929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } finally { 8930d5d3b7cc8b9ff142269a947443c758cb2af4684Robert Shih file.close(); 8949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else if (mFd != null) { 896e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang _setOutputFile(mFd); 8979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else { 8989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throw new IOException("No valid output file"); 8999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 900b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra 9019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project _prepare(); 9029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Begins capturing and encoding data to the file specified with 9069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFile(). Call this after prepare(). 9079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 90842419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * <p>Since API level 13, if applications set a camera via 90942419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * {@link #setCamera(Camera)}, the apps can use the camera after this method 910528b084be26ff6f5b5d8cf42007bf964857be8daWu-cheng Li * call. The apps do not need to lock the camera again. However, if this 911528b084be26ff6f5b5d8cf42007bf964857be8daWu-cheng Li * method fails, the apps should still lock the camera back. The apps should 912528b084be26ff6f5b5d8cf42007bf964857be8daWu-cheng Li * not start another recording session during recording. 91342419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * 9149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 915ac06177a13bb4b9e4685febabd12ff413f759e87Mark Goldstein * prepare() or when the camera is already in use by another app. 9169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void start() throws IllegalStateException; 9189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Stops recording. Call this after start(). Once recording is stopped, 9219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you will have to configure it again as if it has just been constructed. 92222bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * Note that a RuntimeException is intentionally thrown to the 92322bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * application, if no valid audio/video data has been received when stop() 92422bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * is called. This happens if stop() is called immediately after 92522bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * start(). The failure lets the application take action accordingly to 92622bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * clean up the output file (delete the output file, for instance), since 92722bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * the output file is not properly constructed when this happens. 9289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 9299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before start() 9309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void stop() throws IllegalStateException; 9329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 93483995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * Pauses recording. Call this after start(). You may resume recording 93583995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * with resume() without reconfiguration, as opposed to stop(). It does 93683995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * nothing if the recording is already paused. 93783995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * 93883995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * When the recording is paused and resumed, the resulting output would 93983995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * be as if nothing happend during paused period, immediately switching 94083995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * to the resumed scene. 94183995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * 94283995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * @throws IllegalStateException if it is called before start() or after 94383995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * stop() 94483995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim */ 94583995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim public native void pause() throws IllegalStateException; 94683995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim 94783995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim /** 94883995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * Resumes recording. Call this after start(). It does nothing if the 94983995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * recording is not paused. 95083995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * 95183995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * @throws IllegalStateException if it is called before start() or after 95283995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * stop() 95383995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * @see android.media.MediaRecorder#pause 95483995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim */ 95583995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim public native void resume() throws IllegalStateException; 95683995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim 95783995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim /** 9589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Restarts the MediaRecorder to its idle state. After calling 9599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this method, you will have to configure it again as if it had just been 9609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * constructed. 9619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void reset() { 9639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_reset(); 9649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // make sure none of the listeners get called anymore 9669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler.removeCallbacksAndMessages(null); 9679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native void native_reset(); 9709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the maximum absolute amplitude that was sampled since the last 9739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * call to this method. Call this only after the setAudioSource(). 9749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 9759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the maximum absolute amplitude measured since the last call, or 9769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 0 when called for the first time 9779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 9789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the audio source has been set. 9799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native int getMaxAmplitude() throws IllegalStateException; 9819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change this value without updating its counterpart 983a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong * in include/media/mediarecorder.h or mediaplayer.h! 9849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** Unspecified media recorder error. 9869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.OnErrorListener 9879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int MEDIA_RECORDER_ERROR_UNKNOWN = 1; 989a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong /** Media server died. In this case, the application must release the 990a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong * MediaRecorder object and instantiate a new one. 991a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong * @see android.media.MediaRecorder.OnErrorListener 992a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong */ 993a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong public static final int MEDIA_ERROR_SERVER_DIED = 100; 9949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Interface definition for a callback to be invoked when an error 9979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * occurs while recording. 9989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public interface OnErrorListener 10009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 10019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 10029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Called when an error occurs while recording. 10032bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang * 10049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param mr the MediaRecorder that encountered the error 10059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param what the type of error that has occurred: 10069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ul> 10079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>{@link #MEDIA_RECORDER_ERROR_UNKNOWN} 1008a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong * <li>{@link #MEDIA_ERROR_SERVER_DIED} 10099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ul> 10109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param extra an extra code, specific to the error type 10119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project void onError(MediaRecorder mr, int what, int extra); 10139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 10169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Register a callback to be invoked when an error occurs while 10179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recording. 10189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 10199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param l the callback that will be run 10209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setOnErrorListener(OnErrorListener l) 10229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 10239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnErrorListener = l; 10249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1026ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /* Do not change these values without updating their counterparts 1027ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * in include/media/mediarecorder.h! 1028ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 10296f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih /** Unspecified media recorder info. 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_UNKNOWN = 1; 1033ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /** A maximum duration had been setup and has now been reached. 1034ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * @see android.media.MediaRecorder.OnInfoListener 1035ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 1036ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project public static final int MEDIA_RECORDER_INFO_MAX_DURATION_REACHED = 800; 1037105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project /** A maximum filesize had been setup and has now been reached. 1038e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * Note: This event will not be sent if application already set 1039e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * next output file through {@link #setNextOutputFile}. 1040105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * @see android.media.MediaRecorder.OnInfoListener 1041105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project */ 1042105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project public static final int MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED = 801; 1043e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang /** A maximum filesize had been setup and current recorded file size 1044e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * has reached 90% of the limit. This is sent once per file upon 1045e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * reaching/passing the 90% limit. To continue the recording, applicaiton 1046e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * should use {@link #setNextOutputFile} to set the next output file. 1047e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * Otherwise, recording will stop when reaching maximum file size. 1048e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @see android.media.MediaRecorder.OnInfoListener 1049e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang */ 1050e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang public static final int MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING = 802; 1051e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang /** A maximum filesize had been reached and MediaRecorder has switched 1052e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * output to a new file set by application {@link #setNextOutputFile}. 1053e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * For best practice, application should use this event to keep track 1054e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * of whether the file previously set has been used or not. 1055e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @see android.media.MediaRecorder.OnInfoListener 1056e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang */ 1057e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang public static final int MEDIA_RECORDER_INFO_NEXT_OUTPUT_FILE_STARTED = 803; 1058ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 10599e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** informational events for individual tracks, for testing purpose. 10609e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * The track informational event usually contains two parts in the ext1 10619e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * arg of the onInfo() callback: bit 31-28 contains the track id; and 10629e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * the rest of the 28 bits contains the informational event defined here. 10639e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * For example, ext1 = (1 << 28 | MEDIA_RECORDER_TRACK_INFO_TYPE) if the 10649e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * track id is 1 for informational event MEDIA_RECORDER_TRACK_INFO_TYPE; 10659e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * while ext1 = (0 << 28 | MEDIA_RECORDER_TRACK_INFO_TYPE) if the track 10669e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * id is 0 for informational event MEDIA_RECORDER_TRACK_INFO_TYPE. The 10679e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * application should extract the track id and the type of informational 10689e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * event from ext1, accordingly. 10699e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * 10709e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * FIXME: 10719e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * Please update the comment for onInfo also when these 10729e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * events are unhidden so that application knows how to extract the track 10739e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * id and the informational event type from onInfo callback. 10749e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * 10759e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 10769e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 10779e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_LIST_START = 1000; 10789e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Signal the completion of the track for the recording session. 10799e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 10809e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 10819e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_COMPLETION_STATUS = 1000; 10829e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Indicate the recording progress in time (ms) during recording. 10839e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 10849e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 10859e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_PROGRESS_IN_TIME = 1001; 10869e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Indicate the track type: 0 for Audio and 1 for Video. 10879e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 10889e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 10899e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_TYPE = 1002; 10909e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the track duration information. 10919e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 10929e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 10939e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_DURATION_MS = 1003; 10949e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the max chunk duration in time (ms) for the given track. 10959e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 10969e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 10979e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_MAX_CHUNK_DUR_MS = 1004; 10989e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the total number of recordd frames. 10999e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11009e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11019e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_ENCODED_FRAMES = 1005; 11029e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the max spacing between neighboring chunks for the given track. 11039e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11049e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11059e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INTER_CHUNK_TIME_MS = 1006; 11069e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the elapsed time measuring from the start of the recording 11079e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * till the first output frame of the given track is received, excluding 11089e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * any intentional start time offset of a recording session for the 11099e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * purpose of eliminating the recording sound in the recorded file. 11109e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11119e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11129e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_INITIAL_DELAY_MS = 1007; 11139e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the start time difference (delay) betweeen this track and 11149e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * the start of the movie. 11159e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11169e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11179e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_START_OFFSET_MS = 1008; 11180f32fb3ecfdfaa03acf880a356629d43da3fe2feJames Dong /** Provide the total number of data (in kilo-bytes) encoded. 11190f32fb3ecfdfaa03acf880a356629d43da3fe2feJames Dong * {@hide} 11200f32fb3ecfdfaa03acf880a356629d43da3fe2feJames Dong */ 11210f32fb3ecfdfaa03acf880a356629d43da3fe2feJames Dong public static final int MEDIA_RECORDER_TRACK_INFO_DATA_KBYTES = 1009; 11229e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** 11239e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11249e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11259e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_LIST_END = 2000; 11269e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong 11279e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong 1128ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /** 11296f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * Interface definition of a callback to be invoked to communicate some 11306f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * info and/or warning about the recording. 1131ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 1132ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project public interface OnInfoListener 1133ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project { 1134ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /** 11356f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * Called to indicate an info or a warning during recording. 11362bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang * 11376f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * @param mr the MediaRecorder the info pertains to 11386f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * @param what the type of info or warning that has occurred 1139ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * <ul> 1140ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * <li>{@link #MEDIA_RECORDER_INFO_UNKNOWN} 1141105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * <li>{@link #MEDIA_RECORDER_INFO_MAX_DURATION_REACHED} 1142105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * <li>{@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED} 1143ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * </ul> 11446f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * @param extra an extra code, specific to the info type 1145ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 1146ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project void onInfo(MediaRecorder mr, int what, int extra); 1147ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project } 1148ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 1149ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /** 1150ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * Register a callback to be invoked when an informational event occurs while 1151ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * recording. 1152ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * 1153ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * @param listener the callback that will be run 1154ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 1155ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project public void setOnInfoListener(OnInfoListener listener) 1156ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project { 1157ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project mOnInfoListener = listener; 1158ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project } 1159ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 11609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private class EventHandler extends Handler 11619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 11629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private MediaRecorder mMediaRecorder; 11639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 11649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public EventHandler(MediaRecorder mr, Looper looper) { 11659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project super(looper); 11669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mMediaRecorder = mr; 11679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 11689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1169ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /* Do not change these values without updating their counterparts 11709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediarecorder.h! 11719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 11729e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_EVENT_LIST_START = 1; 11739e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_EVENT_ERROR = 1; 11749e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_EVENT_INFO = 2; 11759e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_EVENT_LIST_END = 99; 11769e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong 11779e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /* Events related to individual tracks */ 11789e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_TRACK_EVENT_LIST_START = 100; 11799e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_TRACK_EVENT_ERROR = 100; 11809e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_TRACK_EVENT_INFO = 101; 11819e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_TRACK_EVENT_LIST_END = 1000; 11829e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong 11839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 11849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @Override 11859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void handleMessage(Message msg) { 11869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mMediaRecorder.mNativeContext == 0) { 11879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.w(TAG, "mediarecorder went away with unhandled events"); 11889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 11899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 11909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project switch(msg.what) { 11919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project case MEDIA_RECORDER_EVENT_ERROR: 11929e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong case MEDIA_RECORDER_TRACK_EVENT_ERROR: 11939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mOnErrorListener != null) 11949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnErrorListener.onError(mMediaRecorder, msg.arg1, msg.arg2); 11959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 11969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 11979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1198ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project case MEDIA_RECORDER_EVENT_INFO: 11999e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong case MEDIA_RECORDER_TRACK_EVENT_INFO: 1200ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project if (mOnInfoListener != null) 1201ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project mOnInfoListener.onInfo(mMediaRecorder, msg.arg1, msg.arg2); 1202ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 1203ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project return; 1204ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 12059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project default: 12069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.e(TAG, "Unknown message type " + msg.what); 12079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 12089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 12139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Called from native code when an interesting event happens. This method 12149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * just uses the EventHandler system to post the event back to the main app thread. 12159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * We use a weak reference to the original MediaRecorder object so that the native 12169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * code is safe from the object disappearing from underneath it. (This is 12179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the cookie passed to native_setup().) 12189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 12199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private static void postEventFromNative(Object mediarecorder_ref, 12209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project int what, int arg1, int arg2, Object obj) 12219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 12229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project MediaRecorder mr = (MediaRecorder)((WeakReference)mediarecorder_ref).get(); 12239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mr == null) { 12249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 12259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mr.mEventHandler != null) { 12289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Message m = mr.mEventHandler.obtainMessage(what, arg1, arg2, obj); 12299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mr.mEventHandler.sendMessage(m); 12309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 12349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Releases resources associated with this MediaRecorder object. 12359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * It is good practice to call this method when you're done 123689ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * using the MediaRecorder. In particular, whenever an Activity 123789ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * of an application is paused (its onPause() method is called), 123889ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * or stopped (its onStop() method is called), this method should be 123989ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * invoked to release the MediaRecorder object, unless the application 124089ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * has a special need to keep the object around. In addition to 124189ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * unnecessary resources (such as memory and instances of codecs) 124289ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * being held, failure to call this method immediately if a 124389ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * MediaRecorder object is no longer needed may also lead to 124489ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * continuous battery consumption for mobile devices, and recording 124589ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * failure for other applications if no multiple instances of the 124689ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * same codec are supported on a device. Even if multiple instances 124789ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * of the same codec are supported, some performance degradation 124889ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * may be expected when unnecessary multiple instances are used 124989ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * at the same time. 12509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 12519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void release(); 12529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12534935d05eaa306cef88cf0ab13eca386f270409ecMarco Nelissen private static native final void native_init(); 12544935d05eaa306cef88cf0ab13eca386f270409ecMarco Nelissen 1255788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala private native final void native_setup(Object mediarecorder_this, 1256fa5ecdc4ac6d7a8db2bb9e4a6a60a3189025df30Svet Ganov String clientName, String opPackageName) throws IllegalStateException; 12579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native final void native_finalize(); 12599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12600fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong private native void setParameter(String nameValuePair); 12610fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong 1262b0bd62f96cd81f5209ea01e4f484f5b35a389cc0Ray Essick /** 1263f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick * Return Metrics data about the current Mediarecorder instance. 1264b0bd62f96cd81f5209ea01e4f484f5b35a389cc0Ray Essick * 1265f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick * @return a MediaMetricsSet containing the set of attributes and values 1266f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick * available for the media being generated by this instance of 1267f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick * MediaRecorder. 1268f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick * The attributes are descibed in {@link MediaMetricsSet.MediaRecorder}. 1269b0bd62f96cd81f5209ea01e4f484f5b35a389cc0Ray Essick * 1270f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick * Additional vendor-specific fields may also be present in 1271f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick * the return value. 1272f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick */ 1273f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick public MediaMetricsSet getMetrics() { 1274f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick Bundle bundle = native_getMetrics(); 1275f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick MediaMetricsSet mSet = new MediaMetricsSet(bundle); 1276f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick return mSet; 1277f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick } 1278f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick 1279f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick private native Bundle native_getMetrics(); 1280b0bd62f96cd81f5209ea01e4f484f5b35a389cc0Ray Essick 12819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @Override 12829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project protected void finalize() { native_finalize(); } 12839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 1284