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; 20f11d805d3095dfe4b16bc13436e10c86aabc34a3Jean-Michel Triviimport android.annotation.RequiresPermission; 2100a009204e51997249d60eab4f147eff566e2b1fEric Laurentimport android.annotation.SystemApi; 22788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvalaimport android.app.ActivityThread; 239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.hardware.Camera; 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; 2810353e36018224b86ef2918d1d68107459d445cfRay Essickimport android.os.PersistableBundle; 29589f6a299ed464cf70a953992b5013d8b275099cjiabinimport android.text.TextUtils; 30fe3e6024ed03de26e44df9d366f30a09f00485c8jiabinimport android.util.ArrayMap; 319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.util.Log; 32589a236acfeaec27bc3465b69ca9c701a2f65810jiabinimport android.util.Pair; 339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport android.view.Surface; 3442419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li 355ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuangimport java.io.File; 369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.io.FileDescriptor; 3742419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Liimport java.io.IOException; 380d5d3b7cc8b9ff142269a947443c758cb2af4684Robert Shihimport java.io.RandomAccessFile; 399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectimport java.lang.ref.WeakReference; 40589f6a299ed464cf70a953992b5013d8b275099cjiabinimport java.util.ArrayList; 41589f6a299ed464cf70a953992b5013d8b275099cjiabinimport java.util.List; 429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 43fe3e6024ed03de26e44df9d366f30a09f00485c8jiabinimport com.android.internal.annotations.GuardedBy; 44fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin 459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/** 469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Used to record audio and video. The recording control is based on a 479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * simple state machine (see below). 489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p><img src="{@docRoot}images/mediarecorder_state_diagram.gif" border="0" /> 509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </p> 519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <p>A common case of using MediaRecorder to record audio works as follows: 539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <pre>MediaRecorder recorder = new MediaRecorder(); 559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.setOutputFile(PATH_NAME); 599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.prepare(); 609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.start(); // Recording is now started 619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * ... 629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.stop(); 639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.reset(); // You can reuse the object by going back to setAudioSource() step 649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recorder.release(); // Now the object cannot be reused 659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </pre> 669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 679ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * <p>Applications may want to register for informational and error 689ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * events in order to be informed of some internal update and possible 699ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * runtime errors during recording. Registration for such events is 709ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * done by setting the appropriate listeners (via calls 719ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * (to {@link #setOnInfoListener(OnInfoListener)}setOnInfoListener and/or 729ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * {@link #setOnErrorListener(OnErrorListener)}setOnErrorListener). 739ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * In order to receive the respective callback associated with these listeners, 749ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * applications are required to create MediaRecorder objects on threads with a 759ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * Looper running (the main UI thread by default already has a Looper running). 769ddb7888b4b8c7b1f9e352347d84ae530e47a77dJames Dong * 7761fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <p><strong>Note:</strong> Currently, MediaRecorder does not work on the emulator. 7861fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * 7961fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <div class="special reference"> 8061fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <h3>Developer Guides</h3> 8161fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <p>For more information about how to use MediaRecorder for recording video, read the 8261fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <a href="{@docRoot}guide/topics/media/camera.html#capture-video">Camera</a> developer guide. 8361fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * For more information about how to use MediaRecorder for recording sound, read the 8461fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * <a href="{@docRoot}guide/topics/media/audio-capture.html">Audio Capture</a> developer guide.</p> 8561fd1e8d8c3ccf2d6b7d4af1c19e8f0988d5a1ecJoe Fernandez * </div> 869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 87fe3e6024ed03de26e44df9d366f30a09f00485c8jiabinpublic class MediaRecorder implements AudioRouting 889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project{ 899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project static { 909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project System.loadLibrary("media_jni"); 914935d05eaa306cef88cf0ab13eca386f270409ecMarco Nelissen native_init(); 929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private final static String TAG = "MediaRecorder"; 949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // The two fields below are accessed by native methods 969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @SuppressWarnings("unused") 97075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat private long mNativeContext; 989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @SuppressWarnings("unused") 1009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private Surface mSurface; 1019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private String mPath; 1039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private FileDescriptor mFd; 1045ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang private File mFile; 1059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private EventHandler mEventHandler; 1069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private OnErrorListener mOnErrorListener; 107ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project private OnInfoListener mOnInfoListener; 1089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 109589a236acfeaec27bc3465b69ca9c701a2f65810jiabin private int mChannelCount; 110589a236acfeaec27bc3465b69ca9c701a2f65810jiabin 1119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 1129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Default constructor. 1139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public MediaRecorder() { 1159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Looper looper; 1179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if ((looper = Looper.myLooper()) != null) { 1189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler = new EventHandler(this, looper); 1199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else if ((looper = Looper.getMainLooper()) != null) { 1209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler = new EventHandler(this, looper); 1219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else { 1229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler = null; 1239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 125589a236acfeaec27bc3465b69ca9c701a2f65810jiabin mChannelCount = 1; 126788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala String packageName = ActivityThread.currentPackageName(); 1279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Native setup requires a weak reference to our object. 1289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * It's easier to create it here than in C++. 1299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 130fbf0ecabac5d7a929628b43ffe8f4f953e47bd54Svetoslav native_setup(new WeakReference<MediaRecorder>(this), packageName, 131fbf0ecabac5d7a929628b43ffe8f4f953e47bd54Svetoslav ActivityThread.currentOpPackageName()); 1329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 135b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * Sets a {@link android.hardware.Camera} to use for recording. 136b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * 137b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * <p>Use this function to switch quickly between preview and capture mode without a teardown of 138b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * the camera object. {@link android.hardware.Camera#unlock()} should be called before 139b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * this. Must call before {@link #prepare}.</p> 1409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param c the Camera to use for recording 142b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * @deprecated Use {@link #getSurface} and the {@link android.hardware.camera2} API instead. 1439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 144b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala @Deprecated 1459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setCamera(Camera c); 1469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 14883cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * Gets the surface to record from when using SURFACE video source. 149b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * 150b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * <p> May only be called after {@link #prepare}. Frames rendered to the Surface before 151b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * {@link #start} will be discarded.</p> 152b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * 153b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * @throws IllegalStateException if it is called before {@link #prepare}, after 154b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * {@link #stop}, or is called when VideoSource is not set to SURFACE. 15583cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * @see android.media.MediaRecorder.VideoSource 15683cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang */ 15783cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang public native Surface getSurface(); 15883cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang 15983cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang /** 16017d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * Configures the recorder to use a persistent surface when using SURFACE video source. 16103359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang * <p> May only be called before {@link #prepare}. If called, {@link #getSurface} should 16203359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang * not be used and will throw IllegalStateException. Frames rendered to the Surface 16303359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang * before {@link #start} will be discarded.</p> 16417d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar 16517d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * @param surface a persistent input surface created by 16617d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * {@link MediaCodec#createPersistentInputSurface} 16703359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang * @throws IllegalStateException if it is called after {@link #prepare} and before 16803359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang * {@link #stop}. 16917d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * @throws IllegalArgumentException if the surface was not created by 17017d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * {@link MediaCodec#createPersistentInputSurface}. 17117d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * @see MediaCodec#createPersistentInputSurface 17217d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar * @see MediaRecorder.VideoSource 17317d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar */ 1749560ddb48af0e2da7743452f8d9d6d9cd34d8438Chong Zhang public void setInputSurface(@NonNull Surface surface) { 17503359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang if (!(surface instanceof MediaCodec.PersistentSurface)) { 17603359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang throw new IllegalArgumentException("not a PersistentSurface"); 17703359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang } 1789560ddb48af0e2da7743452f8d9d6d9cd34d8438Chong Zhang native_setInputSurface(surface); 17917d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar } 18017d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar 1819560ddb48af0e2da7743452f8d9d6d9cd34d8438Chong Zhang private native final void native_setInputSurface(@NonNull Surface surface); 18203359161734eb0bdfacb6ff91be8617b9c5eccabChong Zhang 18317d79047c7c3919e75ce0d4bc1eb062528818212Lajos Molnar /** 1849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets a Surface to show a preview of recorded media (video). Calls this 1859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * before prepare() to make sure that the desirable preview display is 186c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * set. If {@link #setCamera(Camera)} is used and the surface has been 187c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * already set to the camera, application do not need to call this. If 188c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * this is called with non-null surface, the preview surface of the camera 189c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * will be replaced by the new surface. If this method is called with null 190c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * surface or not called at all, media recorder will not change the preview 191c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * surface of the camera. 1929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 1939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param sv the Surface to use for the preview 194c59d1a8f0ccbf8d95c8f29cfe9d955d081807fc9Wu-cheng Li * @see android.hardware.Camera#setPreviewDisplay(android.view.SurfaceHolder) 1959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 1969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setPreviewDisplay(Surface sv) { 1979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mSurface = sv; 1989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 2017af0d66c2270d2b804b029bf33d6d8b532625a74Jean-Michel Trivi * Defines the audio source. 2027af0d66c2270d2b804b029bf33d6d8b532625a74Jean-Michel Trivi * An audio source defines both a default physical source of audio signal, and a recording 203fd3ac3da172b877c6f316de2d066883e7a2d0631Jean-Michel Trivi * configuration. These constants are for instance used 2047af0d66c2270d2b804b029bf33d6d8b532625a74Jean-Michel Trivi * in {@link MediaRecorder#setAudioSource(int)} or 205fd3ac3da172b877c6f316de2d066883e7a2d0631Jean-Michel Trivi * {@link AudioRecord.Builder#setAudioSource(int)}. 2069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final class AudioSource { 208701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi 209701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi private AudioSource() {} 210701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi 211701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi /** @hide */ 212701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi public final static int AUDIO_SOURCE_INVALID = -1; 213701d6ff12f36bf5e9de0dafdaced06744fd411ebJean-Michel Trivi 2149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 215b2b292317482d00d067bc91669322b273be61926Rom Lemarchand * in system/media/audio/include/system/audio.h! 2169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2170f0fbd9441f40c6f99470b89774e397f99bf61ebGlenn Kasten 2180f0fbd9441f40c6f99470b89774e397f99bf61ebGlenn Kasten /** Default audio source **/ 2199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT = 0; 2200f0fbd9441f40c6f99470b89774e397f99bf61ebGlenn Kasten 2219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** Microphone audio source */ 2229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int MIC = 1; 2234bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent 224851a8797bd6db96152a7867f4a52b146e25641feEric Laurent /** Voice call uplink (Tx) audio source. 225851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * <p> 226851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * Capturing from <code>VOICE_UPLINK</code> source requires the 227851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * {@link android.Manifest.permission#CAPTURE_AUDIO_OUTPUT} permission. 228851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * This permission is reserved for use by system components and is not available to 229851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * third-party applications. 230851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * </p> 231851a8797bd6db96152a7867f4a52b146e25641feEric Laurent */ 2324bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent public static final int VOICE_UPLINK = 2; 2334bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent 234851a8797bd6db96152a7867f4a52b146e25641feEric Laurent /** Voice call downlink (Rx) audio source. 235851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * <p> 236851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * Capturing from <code>VOICE_DOWNLINK</code> source requires the 237851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * {@link android.Manifest.permission#CAPTURE_AUDIO_OUTPUT} permission. 238851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * This permission is reserved for use by system components and is not available to 239851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * third-party applications. 240851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * </p> 241851a8797bd6db96152a7867f4a52b146e25641feEric Laurent */ 2424bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent public static final int VOICE_DOWNLINK = 3; 2434bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent 244851a8797bd6db96152a7867f4a52b146e25641feEric Laurent /** Voice call uplink + downlink audio source 245851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * <p> 246851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * Capturing from <code>VOICE_CALL</code> source requires the 247851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * {@link android.Manifest.permission#CAPTURE_AUDIO_OUTPUT} permission. 248851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * This permission is reserved for use by system components and is not available to 249851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * third-party applications. 250851a8797bd6db96152a7867f4a52b146e25641feEric Laurent * </p> 251851a8797bd6db96152a7867f4a52b146e25641feEric Laurent */ 2524bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent public static final int VOICE_CALL = 4; 2536869df3a5db0ca0037394f0fd14aecc1d80b5b42Jean-Michel Trivi 2545d1828ee401156cede1d65257d59d66be281edd3Jean-Michel Trivi /** Microphone audio source tuned for video recording, with the same orientation 2555d1828ee401156cede1d65257d59d66be281edd3Jean-Michel Trivi * as the camera if available. */ 2566869df3a5db0ca0037394f0fd14aecc1d80b5b42Jean-Michel Trivi public static final int CAMCORDER = 5; 2576869df3a5db0ca0037394f0fd14aecc1d80b5b42Jean-Michel Trivi 2585d1828ee401156cede1d65257d59d66be281edd3Jean-Michel Trivi /** Microphone audio source tuned for voice recognition. */ 2596869df3a5db0ca0037394f0fd14aecc1d80b5b42Jean-Michel Trivi public static final int VOICE_RECOGNITION = 6; 260820b9e0d3b6f94fe0b524aebf756ce25df273e6aJean-Michel Trivi 261ffd0eb0f1106b0229694a1a86ce7d6356efcf50dJean-Michel Trivi /** Microphone audio source tuned for voice communications such as VoIP. It 262ffd0eb0f1106b0229694a1a86ce7d6356efcf50dJean-Michel Trivi * will for instance take advantage of echo cancellation or automatic gain control 2635d1828ee401156cede1d65257d59d66be281edd3Jean-Michel Trivi * if available. 264820b9e0d3b6f94fe0b524aebf756ce25df273e6aJean-Michel Trivi */ 265820b9e0d3b6f94fe0b524aebf756ce25df273e6aJean-Michel Trivi public static final int VOICE_COMMUNICATION = 7; 26664dfb604e70b70b7c346768114e05ddfadc09addJeff Brown 26764dfb604e70b70b7c346768114e05ddfadc09addJeff Brown /** 26864dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * Audio source for a submix of audio streams to be presented remotely. 26964dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * <p> 27064dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * An application can use this audio source to capture a mix of audio streams 27164dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * that should be transmitted to a remote receiver such as a Wifi display. 27264dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * While recording is active, these audio streams are redirected to the remote 27364dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * submix instead of being played on the device speaker or headset. 27464dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * </p><p> 27564dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * Certain streams are excluded from the remote submix, including 27664dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * {@link AudioManager#STREAM_RING}, {@link AudioManager#STREAM_ALARM}, 27764dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * and {@link AudioManager#STREAM_NOTIFICATION}. These streams will continue 27864dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * to be presented locally as usual. 27964dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * </p><p> 28064dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * Capturing the remote submix audio requires the 28164dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * {@link android.Manifest.permission#CAPTURE_AUDIO_OUTPUT} permission. 28264dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * This permission is reserved for use by system components and is not available to 28364dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * third-party applications. 28464dfb604e70b70b7c346768114e05ddfadc09addJeff Brown * </p> 28564dfb604e70b70b7c346768114e05ddfadc09addJeff Brown */ 286f11d805d3095dfe4b16bc13436e10c86aabc34a3Jean-Michel Trivi @RequiresPermission(android.Manifest.permission.CAPTURE_AUDIO_OUTPUT) 28764dfb604e70b70b7c346768114e05ddfadc09addJeff Brown public static final int REMOTE_SUBMIX = 8; 288357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent 289a7cc59c3187711d390c5a483d26c463a1bcbd331rago /** Microphone audio source tuned for unprocessed (raw) sound if available, behaves like 290a7cc59c3187711d390c5a483d26c463a1bcbd331rago * {@link #DEFAULT} otherwise. */ 291a7cc59c3187711d390c5a483d26c463a1bcbd331rago public static final int UNPROCESSED = 9; 292a7cc59c3187711d390c5a483d26c463a1bcbd331rago 293357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent /** 29400a009204e51997249d60eab4f147eff566e2b1fEric Laurent * Audio source for capturing broadcast radio tuner output. 295ce4483cb83afb3a42a32ef2cb00cf04d6f9018fdBenson Huang * @hide 296ce4483cb83afb3a42a32ef2cb00cf04d6f9018fdBenson Huang */ 29700a009204e51997249d60eab4f147eff566e2b1fEric Laurent @SystemApi 29800a009204e51997249d60eab4f147eff566e2b1fEric Laurent public static final int RADIO_TUNER = 1998; 299ce4483cb83afb3a42a32ef2cb00cf04d6f9018fdBenson Huang 300ce4483cb83afb3a42a32ef2cb00cf04d6f9018fdBenson Huang /** 301357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * Audio source for preemptible, low-priority software hotword detection 302357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * It presents the same gain and pre processing tuning as {@link #VOICE_RECOGNITION}. 303357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * <p> 304357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * An application should use this audio source when it wishes to do 305357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * always-on software hotword detection, while gracefully giving in to any other application 306357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * that might want to read from the microphone. 307357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * </p> 308357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * This is a hidden audio source. 309357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent * @hide 310357263da0ec2bc2be9d48c1becc3d94288c2f3edEric Laurent */ 31100a009204e51997249d60eab4f147eff566e2b1fEric Laurent @SystemApi 312f11d805d3095dfe4b16bc13436e10c86aabc34a3Jean-Michel Trivi @RequiresPermission(android.Manifest.permission.CAPTURE_AUDIO_HOTWORD) 31300a009204e51997249d60eab4f147eff566e2b1fEric Laurent public static final int HOTWORD = 1999; 3149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 316dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi // TODO make AudioSource static (API change) and move this method inside the AudioSource class 317dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi /** 318dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi * @hide 319dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi * @param source An audio source to test 320dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi * @return true if the source is only visible to system components 321dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi */ 322dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi public static boolean isSystemOnlyAudioSource(int source) { 323dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi switch(source) { 324dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.DEFAULT: 325dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.MIC: 326dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.VOICE_UPLINK: 327dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.VOICE_DOWNLINK: 328dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.VOICE_CALL: 329dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.CAMCORDER: 330dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.VOICE_RECOGNITION: 331dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.VOICE_COMMUNICATION: 332dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi //case REMOTE_SUBMIX: considered "system" as it requires system permissions 333dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi case AudioSource.UNPROCESSED: 334dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi return false; 335dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi default: 336dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi return true; 337dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi } 338dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi } 339dd2772a33949796cb371f0d45bc0ba86f2007bdeJean-Michel Trivi 34066ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi /** @hide */ 34166ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi public static final String toLogFriendlyAudioSource(int source) { 34266ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi switch(source) { 34366ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi case AudioSource.DEFAULT: 34466ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi return "DEFAULT"; 34566ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi case AudioSource.MIC: 34666ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi return "MIC"; 34766ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi case AudioSource.VOICE_UPLINK: 34866ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi return "VOICE_UPLINK"; 34966ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi case AudioSource.VOICE_DOWNLINK: 35066ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi return "VOICE_DOWNLINK"; 35166ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi case AudioSource.VOICE_CALL: 35266ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi return "VOICE_CALL"; 35366ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi case AudioSource.CAMCORDER: 35466ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi return "CAMCORDER"; 35566ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi case AudioSource.VOICE_RECOGNITION: 35666ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi return "VOICE_RECOGNITION"; 35766ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi case AudioSource.VOICE_COMMUNICATION: 35866ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi return "VOICE_COMMUNICATION"; 35966ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi case AudioSource.REMOTE_SUBMIX: 36066ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi return "REMOTE_SUBMIX"; 36166ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi case AudioSource.UNPROCESSED: 36266ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi return "UNPROCESSED"; 36366ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi case AudioSource.RADIO_TUNER: 36466ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi return "RADIO_TUNER"; 36566ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi case AudioSource.HOTWORD: 36666ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi return "HOTWORD"; 36766ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi case AudioSource.AUDIO_SOURCE_INVALID: 36866ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi return "AUDIO_SOURCE_INVALID"; 36966ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi default: 37066ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi return "unknown source " + source; 37166ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi } 37266ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi } 37366ffacf42a7dde6fac867605aaa47d555b960ee4Jean-Michel Trivi 3749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Defines the video source. These constants are used with 3769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link MediaRecorder#setVideoSource(int)}. 3779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final class VideoSource { 3799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 3809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediarecorder.h! 3819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private VideoSource() {} 3839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT = 0; 38483cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang /** Camera video source 38583cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * <p> 386b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * Using the {@link android.hardware.Camera} API as video source. 38783cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * </p> 38883cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang */ 3899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int CAMERA = 1; 39083cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang /** Surface video source 39183cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * <p> 39283cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * Using a Surface as video source. 39383cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * </p><p> 39483cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * This flag must be used when recording from an 395b942b05093d2b1cee59ac73196a4b99962f10addEino-Ville Talvala * {@link android.hardware.camera2} API source. 39683cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * </p><p> 39783cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * When using this video source type, use {@link MediaRecorder#getSurface()} 39883cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang * to retrieve the surface created by MediaRecorder. 39983cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang */ 40083cc994ba40a7227c62a65ccb5addf3a23ff6350Chong Zhang public static final int SURFACE = 2; 4019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Defines the output format. These constants are used with 4059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link MediaRecorder#setOutputFormat(int)}. 4069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final class OutputFormat { 4089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 4099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediarecorder.h! 4109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private OutputFormat() {} 4129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT = 0; 4139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3GPP media file format*/ 4149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int THREE_GPP = 1; 4159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** MPEG4 media file format*/ 4169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int MPEG_4 = 2; 4172bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang 418874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong /** The following formats are audio only .aac or .amr formats */ 419874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong 420874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong /** 421874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong * AMR NB file format 422874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong * @deprecated Deprecated in favor of MediaRecorder.OutputFormat.AMR_NB 423874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong */ 4249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int RAW_AMR = 3; 425874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong 4262116dc91e96f7153f65468ed40a0b57e437679f7James Dong /** AMR NB file format */ 4272bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AMR_NB = 3; 428874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong 4292116dc91e96f7153f65468ed40a0b57e437679f7James Dong /** AMR WB file format */ 4302bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AMR_WB = 4; 431874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong 4322bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang /** @hide AAC ADIF file format */ 4332bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AAC_ADIF = 5; 434874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong 435874d1f1f65a989405b3c1f692014ef2072e09f5eJames Dong /** AAC ADTS file format */ 4362bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AAC_ADTS = 6; 43757648e4eec7dd2593af467877bc7cce4aa654759Andreas Huber 43857648e4eec7dd2593af467877bc7cce4aa654759Andreas Huber /** @hide Stream over a socket, limited to a single stream */ 43957648e4eec7dd2593af467877bc7cce4aa654759Andreas Huber public static final int OUTPUT_FORMAT_RTP_AVP = 7; 4409adf466021d37a5062d7d3361e14bfd9e7ffeba6Andreas Huber 4415b168a0c549a164898b5f1568b155d02ccce77cdHangyu Kuang /** H.264/AAC data encapsulated in MPEG2/TS */ 4425b168a0c549a164898b5f1568b155d02ccce77cdHangyu Kuang public static final int MPEG_2_TS = 8; 443c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih 444c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih /** VP8/VORBIS data in a WEBM container */ 445c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih public static final int WEBM = 9; 4469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project }; 4479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Defines the audio encoding. These constants are used with 4509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link MediaRecorder#setAudioEncoder(int)}. 4519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final class AudioEncoder { 4539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 4549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediarecorder.h! 4559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private AudioEncoder() {} 4579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT = 0; 4589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** AMR (Narrowband) audio codec */ 4599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int AMR_NB = 1; 4602116dc91e96f7153f65468ed40a0b57e437679f7James Dong /** AMR (Wideband) audio codec */ 4612bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AMR_WB = 2; 462ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke /** AAC Low Complexity (AAC-LC) audio codec */ 4632bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang public static final int AAC = 3; 464ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke /** High Efficiency AAC (HE-AAC) audio codec */ 465ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke public static final int HE_AAC = 4; 466ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke /** Enhanced Low Delay AAC (AAC-ELD) audio codec */ 467ec3f31f6215cb380bba5ab36c9e4c21b13f046a1Dave Burke public static final int AAC_ELD = 5; 468c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih /** Ogg Vorbis audio codec */ 469c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih public static final int VORBIS = 6; 4709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Defines the video encoding. These constants are used with 4749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * {@link MediaRecorder#setVideoEncoder(int)}. 4759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public final class VideoEncoder { 4779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change these values without updating their counterparts 4789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediarecorder.h! 4799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private VideoEncoder() {} 4819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int DEFAULT = 0; 4829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int H263 = 1; 4839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int H264 = 2; 4849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int MPEG_4_SP = 3; 485c20533c1a7772f61d904fad31e3998c055c03da5Robert Shih public static final int VP8 = 4; 486886e562bc5aa51b1bbb3f429a440d1f4e90db1c2Wonsik Kim public static final int HEVC = 5; 4879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the audio source to be used for recording. If this method is not 4919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * called, the output file will not contain an audio track. The source needs 4929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to be specified before setting recording-parameters or encoders. Call 4939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this only before setOutputFormat(). 4949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 4959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param audio_source the audio source to use 4969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after setOutputFormat() 4979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.AudioSource 4989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setAudioSource(int audio_source) 5009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 5019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5034bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent * Gets the maximum value for audio sources. 5044bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent * @see android.media.MediaRecorder.AudioSource 5054bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent */ 5062ac2afeac989ea1dc326b0db996d6c6c8e00cc29Jean-Michel Trivi public static final int getAudioSourceMax() { 507a7cc59c3187711d390c5a483d26c463a1bcbd331rago return AudioSource.UNPROCESSED; 5082ac2afeac989ea1dc326b0db996d6c6c8e00cc29Jean-Michel Trivi } 5094bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent 5104bc035a65cac177be9294e69f110497e3b6e34e6Eric Laurent /** 5119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the video source to be used for recording. If this method is not 5129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * called, the output file will not contain an video track. The source needs 5139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * to be specified before setting recording-parameters or encoders. Call 5149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this only before setOutputFormat(). 5159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 5169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param video_source the video source to use 5179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after setOutputFormat() 5189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.VideoSource 5199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setVideoSource(int video_source) 5219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 5229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 524e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong * Uses the settings from a CamcorderProfile object for recording. This method should 525e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong * be called after the video AND audio sources are set, and before setOutputFile(). 526a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * If a time lapse CamcorderProfile is used, audio related source or recording 527a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * parameters are ignored. 528e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong * 529e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong * @param profile the CamcorderProfile to use 530e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong * @see android.media.CamcorderProfile 531e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong */ 532e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong public void setProfile(CamcorderProfile profile) { 533e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong setOutputFormat(profile.fileFormat); 534e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong setVideoFrameRate(profile.videoFrameRate); 535e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight); 536e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong setVideoEncodingBitRate(profile.videoBitRate); 537e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong setVideoEncoder(profile.videoCodec); 5384f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra if (profile.quality >= CamcorderProfile.QUALITY_TIME_LAPSE_LOW && 53933fe290ca33235d7e0988cace14de3319a9a83f1James Dong profile.quality <= CamcorderProfile.QUALITY_TIME_LAPSE_QVGA) { 540a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong // Nothing needs to be done. Call to setCaptureRate() enables 541a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong // time lapse video recording. 5424f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra } else { 5434f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra setAudioEncodingBitRate(profile.audioBitRate); 5444f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra setAudioChannels(profile.audioChannels); 5454f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra setAudioSamplingRate(profile.audioSampleRate); 5464f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra setAudioEncoder(profile.audioCodec); 5474f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra } 548e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong } 549e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong 550e64d9a236e4704abf53d3b7eea2eb066f23cf402James Dong /** 5514f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * Set video frame capture rate. This can be used to set a different video frame capture 552a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * rate than the recorded video's playback rate. This method also sets the recording mode 553a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * to time lapse. In time lapse video recording, only video is recorded. Audio related 554a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * parameters are ignored when a time lapse recording session starts, if an application 555a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong * sets them. 556ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra * 5574f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * @param fps Rate at which frames should be captured in frames per second. 5584f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * The fps can go as low as desired. However the fastest fps will be limited by the hardware. 5594f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * For resolutions that can be captured by the video camera, the fastest fps can be computed using 5604f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * {@link android.hardware.Camera.Parameters#getPreviewFpsRange(int[])}. For higher 5614f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * resolutions the fastest fps may be more restrictive. 5624f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * Note that the recorder cannot guarantee that frames will be captured at the 5634f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * given rate due to camera/encoder limitations. However it tries to be as close as 5644f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra * possible. 565ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra */ 5664f6bf17407bc2fe89d42537fdf5fc431c82902dbNipun Kwatra public void setCaptureRate(double fps) { 567a4d205d02c0c69fd2a783ef86747058fa00e066eJames Dong // Make sure that time lapse is enabled when this method is called. 5681c7928e8c68654d087f83c7cefc59095950b8befJohan Redestig setParameter("time-lapse-enable=1"); 569fbdee2c04b88210bab5c9a769908be42d1775e16Chong Zhang setParameter("time-lapse-fps=" + fps); 570ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra } 571ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra 572ab15bce98d44b67f221b6fb8a377744940dda46cNipun Kwatra /** 573ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * Sets the orientation hint for output video playback. 5745aa95dd36cd0708d25accd8d745ae8ebc255758fJames Dong * This method should be called before prepare(). This method will not 575ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * trigger the source video frame to rotate during video recording, but to 576ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * add a composition matrix containing the rotation angle in the output 577ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * video if the output format is OutputFormat.THREE_GPP or 578ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * OutputFormat.MPEG_4 so that a video player can choose the proper 579ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * orientation for playback. Note that some video players may choose 580ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * to ignore the compostion matrix in a video during playback. 581ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * 582ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * @param degrees the angle to be rotated clockwise in degrees. 583ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * The supported angles are 0, 90, 180, and 270 degrees. 584ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * @throws IllegalArgumentException if the angle is not supported. 585ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong * 586ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong */ 587ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong public void setOrientationHint(int degrees) { 588ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong if (degrees != 0 && 589ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong degrees != 90 && 590ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong degrees != 180 && 591ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong degrees != 270) { 592ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong throw new IllegalArgumentException("Unsupported angle: " + degrees); 593ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong } 5942450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund setParameter("video-param-rotation-angle-degrees=" + degrees); 595ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong } 596ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong 597ad8f19c6b3167cadc90a35f4d795b07aa2f04ffaJames Dong /** 598af3131fe2e20c7b5e080d098a3b6847c5414bcaeJames Dong * Set and store the geodata (latitude and longitude) in the output file. 599987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * This method should be called before prepare(). The geodata is 600987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * stored in udta box if the output format is OutputFormat.THREE_GPP 601987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * or OutputFormat.MPEG_4, and is ignored for other output formats. 602987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * The geodata is stored according to ISO-6709 standard. 603987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * 604987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * @param latitude latitude in degrees. Its value must be in the 605987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * range [-90, 90]. 606987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * @param longitude longitude in degrees. Its value must be in the 607987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * range [-180, 180]. 608987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * 609987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * @throws IllegalArgumentException if the given latitude or 610987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * longitude is out of range. 611987ab4833ecbafbdf750eb1b04e43693433c4783James Dong * 612987ab4833ecbafbdf750eb1b04e43693433c4783James Dong */ 613af3131fe2e20c7b5e080d098a3b6847c5414bcaeJames Dong public void setLocation(float latitude, float longitude) { 614987ab4833ecbafbdf750eb1b04e43693433c4783James Dong int latitudex10000 = (int) (latitude * 10000 + 0.5); 615987ab4833ecbafbdf750eb1b04e43693433c4783James Dong int longitudex10000 = (int) (longitude * 10000 + 0.5); 616987ab4833ecbafbdf750eb1b04e43693433c4783James Dong 617987ab4833ecbafbdf750eb1b04e43693433c4783James Dong if (latitudex10000 > 900000 || latitudex10000 < -900000) { 618af3131fe2e20c7b5e080d098a3b6847c5414bcaeJames Dong String msg = "Latitude: " + latitude + " out of range."; 619987ab4833ecbafbdf750eb1b04e43693433c4783James Dong throw new IllegalArgumentException(msg); 620987ab4833ecbafbdf750eb1b04e43693433c4783James Dong } 621987ab4833ecbafbdf750eb1b04e43693433c4783James Dong if (longitudex10000 > 1800000 || longitudex10000 < -1800000) { 622af3131fe2e20c7b5e080d098a3b6847c5414bcaeJames Dong String msg = "Longitude: " + longitude + " out of range"; 623987ab4833ecbafbdf750eb1b04e43693433c4783James Dong throw new IllegalArgumentException(msg); 624987ab4833ecbafbdf750eb1b04e43693433c4783James Dong } 625987ab4833ecbafbdf750eb1b04e43693433c4783James Dong 626987ab4833ecbafbdf750eb1b04e43693433c4783James Dong setParameter("param-geotag-latitude=" + latitudex10000); 627987ab4833ecbafbdf750eb1b04e43693433c4783James Dong setParameter("param-geotag-longitude=" + longitudex10000); 628987ab4833ecbafbdf750eb1b04e43693433c4783James Dong } 629987ab4833ecbafbdf750eb1b04e43693433c4783James Dong 630987ab4833ecbafbdf750eb1b04e43693433c4783James Dong /** 6319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the format of the output file produced during recording. Call this 6329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * after setAudioSource()/setVideoSource() but before prepare(). 6339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6342170312ab0b6766e8b73b806efbe6abdbb702bbcDave Sparks * <p>It is recommended to always use 3GP format when using the H.263 6352170312ab0b6766e8b73b806efbe6abdbb702bbcDave Sparks * video encoder and AMR audio encoder. Using an MPEG-4 container format 6362170312ab0b6766e8b73b806efbe6abdbb702bbcDave Sparks * may confuse some desktop players.</p> 6372170312ab0b6766e8b73b806efbe6abdbb702bbcDave Sparks * 6389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param output_format the output format to use. The output format 6399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * needs to be specified before setting recording-parameters or encoders. 6409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after prepare() or before 6419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setAudioSource()/setVideoSource(). 6429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.OutputFormat 6439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setOutputFormat(int output_format) 6459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 6469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the width and height of the video to be captured. Must be called 6499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * after setVideoSource(). Call this after setOutFormat() but before 6509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * prepare(). 6519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param width the width of the video to be captured 6539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param height the height of the video to be captured 6549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after 6559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * prepare() or before setOutputFormat() 6569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setVideoSize(int width, int height) 6589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 6599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the frame rate of the video to be captured. Must be called 6629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * after setVideoSource(). Call this after setOutFormat() but before 6639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * prepare(). 6649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param rate the number of frames per second of video to capture 6669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after 6679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * prepare() or before setOutputFormat(). 6689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * NOTE: On some devices that have auto-frame rate, this sets the 6709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * maximum frame rate, not a constant frame rate. Actual frame rate 6719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * will vary according to lighting conditions. 6729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setVideoFrameRate(int rate) throws IllegalStateException; 6749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 676ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * Sets the maximum duration (in ms) of the recording session. 677ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * Call this after setOutFormat() but before prepare(). 678105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * After recording reaches the specified duration, a notification 679105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * will be sent to the {@link android.media.MediaRecorder.OnInfoListener} 680105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * with a "what" code of {@link #MEDIA_RECORDER_INFO_MAX_DURATION_REACHED} 681105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * and recording will be stopped. Stopping happens asynchronously, there 682105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * is no guarantee that the recorder will have stopped by the time the 683105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * listener is notified. 684ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * 685ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * @param max_duration_ms the maximum duration in ms (if zero or negative, disables the duration limit) 686ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * 687ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 688ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project public native void setMaxDuration(int max_duration_ms) throws IllegalArgumentException; 689ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 690ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /** 691105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * Sets the maximum filesize (in bytes) of the recording session. 692105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * Call this after setOutFormat() but before prepare(). 693105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * After recording reaches the specified filesize, a notification 694105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * will be sent to the {@link android.media.MediaRecorder.OnInfoListener} 695105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * with a "what" code of {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED} 696105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * and recording will be stopped. Stopping happens asynchronously, there 697105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * is no guarantee that the recorder will have stopped by the time the 698105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * listener is notified. 699105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * 700105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * @param max_filesize_bytes the maximum filesize in bytes (if zero or negative, disables the limit) 701105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * 702105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project */ 703105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project public native void setMaxFileSize(long max_filesize_bytes) throws IllegalArgumentException; 704105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project 705105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project /** 7069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the audio encoder to be used for recording. If this method is not 7079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * called, the output file will not contain an audio track. Call this after 7089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() but before prepare(). 7099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 7109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param audio_encoder the audio encoder to use. 7119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 7129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() or after prepare(). 7139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.AudioEncoder 7149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 7159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setAudioEncoder(int audio_encoder) 7169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 7179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 7199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the video encoder to be used for recording. If this method is not 7209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * called, the output file will not contain an video track. Call this after 7219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() and before prepare(). 7229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 7239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param video_encoder the video encoder to use. 7249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 7259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() or after prepare() 7269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.VideoEncoder 7279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 7289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void setVideoEncoder(int video_encoder) 7299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throws IllegalStateException; 7309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 7320fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Sets the audio sampling rate for recording. Call this method before prepare(). 7330fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Prepare() may perform additional checks on the parameter to make sure whether 7340fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * the specified audio sampling rate is applicable. The sampling rate really depends 7350fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * on the format for the audio recording, as well as the capabilities of the platform. 7360fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * For instance, the sampling rate supported by AAC audio coding standard ranges 73754815a78aff9bd453a8f0ac3c02f3a35c4b04146James Dong * from 8 to 96 kHz, the sampling rate supported by AMRNB is 8kHz, and the sampling 73854815a78aff9bd453a8f0ac3c02f3a35c4b04146James Dong * rate supported by AMRWB is 16kHz. Please consult with the related audio coding 73954815a78aff9bd453a8f0ac3c02f3a35c4b04146James Dong * standard for the supported audio sampling rate. 7400fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * 7410fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * @param samplingRate the sampling rate for audio in samples per second. 7420fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong */ 7430fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong public void setAudioSamplingRate(int samplingRate) { 7440fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong if (samplingRate <= 0) { 7450fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong throw new IllegalArgumentException("Audio sampling rate is not positive"); 7460fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7472450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund setParameter("audio-param-sampling-rate=" + samplingRate); 7480fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7490fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong 7500fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong /** 7510fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Sets the number of audio channels for recording. Call this method before prepare(). 7520fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Prepare() may perform additional checks on the parameter to make sure whether the 7530fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * specified number of audio channels are applicable. 7542bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang * 7550fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * @param numChannels the number of audio channels. Usually it is either 1 (mono) or 2 7560fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * (stereo). 7572bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang */ 7580fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong public void setAudioChannels(int numChannels) { 7590fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong if (numChannels <= 0) { 7600fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong throw new IllegalArgumentException("Number of channels is not positive"); 7610fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 762589a236acfeaec27bc3465b69ca9c701a2f65810jiabin mChannelCount = numChannels; 7632450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund setParameter("audio-param-number-of-channels=" + numChannels); 7640fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7650fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong 7660fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong /** 7670fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Sets the audio encoding bit rate for recording. Call this method before prepare(). 7680fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Prepare() may perform additional checks on the parameter to make sure whether the 7690fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * specified bit rate is applicable, and sometimes the passed bitRate will be clipped 7700fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * internally to ensure the audio recording can proceed smoothly based on the 7710fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * capabilities of the platform. 7720fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * 7730fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * @param bitRate the audio encoding bit rate in bits per second. 7740fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong */ 7750fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong public void setAudioEncodingBitRate(int bitRate) { 7760fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong if (bitRate <= 0) { 7770fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong throw new IllegalArgumentException("Audio encoding bit rate is not positive"); 7780fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7792450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund setParameter("audio-param-encoding-bitrate=" + bitRate); 7800fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7810fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong 7820fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong /** 7830fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Sets the video encoding bit rate for recording. Call this method before prepare(). 7840fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * Prepare() may perform additional checks on the parameter to make sure whether the 7850fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * specified bit rate is applicable, and sometimes the passed bitRate will be 7860fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * clipped internally to ensure the video recording can proceed smoothly based on 7870fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * the capabilities of the platform. 7880fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * 7890fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong * @param bitRate the video encoding bit rate in bits per second. 7900fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong */ 7910fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong public void setVideoEncodingBitRate(int bitRate) { 7920fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong if (bitRate <= 0) { 7930fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong throw new IllegalArgumentException("Video encoding bit rate is not positive"); 7940fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7952450830c0c41a45d333838f4dcf3ba1e4a2409a2Henrik Backlund setParameter("video-param-encoding-bitrate=" + bitRate); 7960fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong } 7972bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang 7982bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang /** 7999ef7fe43c9cd78382d699882e3b3170a50f62653Hangyu Kuang * Sets the desired video encoding profile and level for recording. The profile and level 8009ef7fe43c9cd78382d699882e3b3170a50f62653Hangyu Kuang * must be valid for the video encoder set by {@link #setVideoEncoder}. This method can 8019ef7fe43c9cd78382d699882e3b3170a50f62653Hangyu Kuang * called before or after {@link #setVideoEncoder} but it must be called before {@link #prepare}. 8029ef7fe43c9cd78382d699882e3b3170a50f62653Hangyu Kuang * {@code prepare()} may perform additional checks on the parameter to make sure that the specified 8039ef7fe43c9cd78382d699882e3b3170a50f62653Hangyu Kuang * profile and level are applicable, and sometimes the passed profile or level will be 8049ef7fe43c9cd78382d699882e3b3170a50f62653Hangyu Kuang * discarded due to codec capablity or to ensure the video recording can proceed smoothly 8059ef7fe43c9cd78382d699882e3b3170a50f62653Hangyu Kuang * based on the capabilities of the platform. <br>Application can also use the 8069ef7fe43c9cd78382d699882e3b3170a50f62653Hangyu Kuang * {@link MediaCodecInfo.CodecCapabilities#profileLevels} to query applicable combination of profile 8079ef7fe43c9cd78382d699882e3b3170a50f62653Hangyu Kuang * and level for the corresponding format. Note that the requested profile/level may not be supported by 8089ef7fe43c9cd78382d699882e3b3170a50f62653Hangyu Kuang * the codec that is actually being used by this MediaRecorder instance. 809f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * @param profile declared in {@link MediaCodecInfo.CodecProfileLevel}. 810f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang * @param level declared in {@link MediaCodecInfo.CodecProfileLevel}. 8119ef7fe43c9cd78382d699882e3b3170a50f62653Hangyu Kuang * @throws IllegalArgumentException when an invalid profile or level value is used. 812f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang */ 813f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang public void setVideoEncodingProfileLevel(int profile, int level) { 814f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang if (profile <= 0) { 815f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang throw new IllegalArgumentException("Video encoding profile is not positive"); 816f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang } 817f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang if (level <= 0) { 818f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang throw new IllegalArgumentException("Video encoding level is not positive"); 819f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang } 820f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang setParameter("video-param-encoder-profile=" + profile); 821f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang setParameter("video-param-encoder-level=" + level); 822f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang } 823f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang 824f70ad43f1366ed58d3eeec714c3917b48ffb54b8Hangyu Kuang /** 8253ff98beeafd271a65c1f824699431366882b04f6James Dong * Currently not implemented. It does nothing. 8263ff98beeafd271a65c1f824699431366882b04f6James Dong * @deprecated Time lapse mode video recording using camera still image capture 8273ff98beeafd271a65c1f824699431366882b04f6James Dong * is not desirable, and will not be supported. 828029d7e15f38cdd3c1941a16186c5941edc85bc3dJames Dong * @hide 829b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra */ 8301fec21be65ddda46fe39c40e00d2fb94a8ce59f1Nipun Kwatra public void setAuxiliaryOutputFile(FileDescriptor fd) 831b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra { 8323ff98beeafd271a65c1f824699431366882b04f6James Dong Log.w(TAG, "setAuxiliaryOutputFile(FileDescriptor) is no longer supported."); 833b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra } 834b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra 835b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra /** 8363ff98beeafd271a65c1f824699431366882b04f6James Dong * Currently not implemented. It does nothing. 8373ff98beeafd271a65c1f824699431366882b04f6James Dong * @deprecated Time lapse mode video recording using camera still image capture 8383ff98beeafd271a65c1f824699431366882b04f6James Dong * is not desirable, and will not be supported. 839029d7e15f38cdd3c1941a16186c5941edc85bc3dJames Dong * @hide 840b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra */ 8411fec21be65ddda46fe39c40e00d2fb94a8ce59f1Nipun Kwatra public void setAuxiliaryOutputFile(String path) 842b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra { 8433ff98beeafd271a65c1f824699431366882b04f6James Dong Log.w(TAG, "setAuxiliaryOutputFile(String) is no longer supported."); 844b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra } 845b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra 846b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra /** 8479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Pass in the file descriptor of the file to be written. Call this after 8489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() but before prepare(). 8499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 8509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param fd an open file descriptor to be written into. 8519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 8529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() or after prepare() 8539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 8549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setOutputFile(FileDescriptor fd) throws IllegalStateException 8559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 8569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mPath = null; 8575ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang mFile = null; 8589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mFd = fd; 8599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 8609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 8619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 8625ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang * Pass in the file object to be written. Call this after setOutputFormat() but before prepare(). 8635ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang * File should be seekable. After setting the next output file, application should not use the 8645ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang * file until {@link #stop}. Application is responsible for cleaning up unused files after 8655ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang * {@link #stop} is called. 8665ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang * 8675ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang * @param file the file object to be written into. 8685ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang */ 8695ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang public void setOutputFile(File file) 8705ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang { 8715ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang mPath = null; 8725ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang mFd = null; 8735ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang mFile = file; 8745ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang } 8755ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang 8765ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang /** 877e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * Sets the next output file descriptor to be used when the maximum filesize is reached 878e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * on the prior output {@link #setOutputFile} or {@link #setNextOutputFile}). File descriptor 87982d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * must be seekable and writable. After setting the next output file, application should not 88082d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * use the file referenced by this file descriptor until {@link #stop}. It is the application's 88182d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * responsibility to close the file descriptor. It is safe to do so as soon as this call returns. 88282d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * Application must call this after receiving on the 88382d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * {@link android.media.MediaRecorder.OnInfoListener} a "what" code of 88482d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING} and before receiving a "what" code of 88582d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED}. The file is not used until switching to 88682d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * that output. Application will receive{@link #MEDIA_RECORDER_INFO_NEXT_OUTPUT_FILE_STARTED} 88782d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * when the next output file is used. Application will not be able to set a new output file if 88882d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * the previous one has not been used. Application is responsible for cleaning up unused files 88982d2ea4a4f2d6dc73c9e84bf0bdd6c79f8c20909Hangyu Kuang * after {@link #stop} is called. 890e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * 891e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @param fd an open file descriptor to be written into. 892e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @throws IllegalStateException if it is called before prepare(). 893e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @throws IOException if setNextOutputFile fails otherwise. 894e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang */ 895c481c50a4254ed0072246c1e771a28154f6161a3Hangyu Kuang public void setNextOutputFile(FileDescriptor fd) throws IOException 896e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang { 897e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang _setNextOutputFile(fd); 898e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang } 899e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang 900e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang /** 9019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the path of the output file to be produced. Call this after 9029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() but before prepare(). 9039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 9049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param path The pathname to use. 9059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 9069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFormat() or after prepare() 9079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setOutputFile(String path) throws IllegalStateException 9099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 9109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mFd = null; 9115ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang mFile = null; 9129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mPath = path; 9139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 915e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang /** 9165ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang * Sets the next output file to be used when the maximum filesize is reached on the prior 9175ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang * output {@link #setOutputFile} or {@link #setNextOutputFile}). File should be seekable. 9185ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang * After setting the next output file, application should not use the file until {@link #stop}. 9195ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang * Application must call this after receiving on the 9205ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang * {@link android.media.MediaRecorder.OnInfoListener} a "what" code of 921e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING} and before receiving a "what" code of 922e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * {@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED}. The file is not used until switching to 923e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * that output. Application will receive {@link #MEDIA_RECORDER_INFO_NEXT_OUTPUT_FILE_STARTED} 924e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * when the next output file is used. Application will not be able to set a new output file if 925e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * the previous one has not been used. Application is responsible for cleaning up unused files 926e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * after {@link #stop} is called. 927e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * 9285ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang * @param file The file to use. 929e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @throws IllegalStateException if it is called before prepare(). 930e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @throws IOException if setNextOutputFile fails otherwise. 931e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang */ 932c481c50a4254ed0072246c1e771a28154f6161a3Hangyu Kuang public void setNextOutputFile(File file) throws IOException 933e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang { 934404802c00150973e420a396b883e28ca217939f9Hangyu Kuang RandomAccessFile f = new RandomAccessFile(file, "rw"); 9355ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang try { 9365ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang _setNextOutputFile(f.getFD()); 9375ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang } finally { 9385ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang f.close(); 939e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang } 940e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang } 941e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang 9429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // native implementation 943e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang private native void _setOutputFile(FileDescriptor fd) throws IllegalStateException, IOException; 944e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang private native void _setNextOutputFile(FileDescriptor fd) throws IllegalStateException, IOException; 9459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native void _prepare() throws IllegalStateException, IOException; 9469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Prepares the recorder to begin capturing and encoding data. This method 9499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * must be called after setting up the desired audio and video sources, 9509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * encoders, file format, etc., but before start(). 9519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 9529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called after 9539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * start() or before setOutputFormat(). 9549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IOException if prepare fails otherwise. 9559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void prepare() throws IllegalStateException, IOException 9579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 9589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mPath != null) { 959404802c00150973e420a396b883e28ca217939f9Hangyu Kuang RandomAccessFile file = new RandomAccessFile(mPath, "rw"); 9609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 961e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang _setOutputFile(file.getFD()); 9629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } finally { 9630d5d3b7cc8b9ff142269a947443c758cb2af4684Robert Shih file.close(); 9649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else if (mFd != null) { 966e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang _setOutputFile(mFd); 9675ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang } else if (mFile != null) { 968404802c00150973e420a396b883e28ca217939f9Hangyu Kuang RandomAccessFile file = new RandomAccessFile(mFile, "rw"); 9695ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang try { 9705ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang _setOutputFile(file.getFD()); 9715ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang } finally { 9725ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang file.close(); 9735ba5e9182c72ad324bb90af1316c68b5792b5b2eHangyu Kuang } 9749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } else { 9759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throw new IOException("No valid output file"); 9769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 977b33a5aea130b025f30966828562fcba56f25b265Nipun Kwatra 9789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project _prepare(); 9799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 9809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Begins capturing and encoding data to the file specified with 9839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * setOutputFile(). Call this after prepare(). 9849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 98542419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * <p>Since API level 13, if applications set a camera via 98642419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * {@link #setCamera(Camera)}, the apps can use the camera after this method 987528b084be26ff6f5b5d8cf42007bf964857be8daWu-cheng Li * call. The apps do not need to lock the camera again. However, if this 988528b084be26ff6f5b5d8cf42007bf964857be8daWu-cheng Li * method fails, the apps should still lock the camera back. The apps should 989528b084be26ff6f5b5d8cf42007bf964857be8daWu-cheng Li * not start another recording session during recording. 99042419ce28a09eb63e29a8fef87e6f5534f41902fWu-cheng Li * 9919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 992ac06177a13bb4b9e4685febabd12ff413f759e87Mark Goldstein * prepare() or when the camera is already in use by another app. 9939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 9949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void start() throws IllegalStateException; 9959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 9969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 9979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Stops recording. Call this after start(). Once recording is stopped, 9989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you will have to configure it again as if it has just been constructed. 99922bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * Note that a RuntimeException is intentionally thrown to the 100022bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * application, if no valid audio/video data has been received when stop() 100122bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * is called. This happens if stop() is called immediately after 100222bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * start(). The failure lets the application take action accordingly to 100322bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * clean up the output file (delete the output file, for instance), since 100422bf7a7ea768c2cdadc5faf643aba70aebafc0d5James Dong * the output file is not properly constructed when this happens. 10059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 10069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before start() 10079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void stop() throws IllegalStateException; 10099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 101183995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * Pauses recording. Call this after start(). You may resume recording 101283995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * with resume() without reconfiguration, as opposed to stop(). It does 101383995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * nothing if the recording is already paused. 101483995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * 101583995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * When the recording is paused and resumed, the resulting output would 101683995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * be as if nothing happend during paused period, immediately switching 101783995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * to the resumed scene. 101883995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * 101983995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * @throws IllegalStateException if it is called before start() or after 102083995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * stop() 102183995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim */ 102283995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim public native void pause() throws IllegalStateException; 102383995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim 102483995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim /** 102583995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * Resumes recording. Call this after start(). It does nothing if the 102683995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * recording is not paused. 102783995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * 102883995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * @throws IllegalStateException if it is called before start() or after 102983995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * stop() 103083995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim * @see android.media.MediaRecorder#pause 103183995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim */ 103283995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim public native void resume() throws IllegalStateException; 103383995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim 103483995063178674f1cd18f32d1e7c37046680d8bdWonsik Kim /** 10359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Restarts the MediaRecorder to its idle state. After calling 10369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this method, you will have to configure it again as if it had just been 10379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * constructed. 10389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void reset() { 10409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_reset(); 10419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // make sure none of the listeners get called anymore 10439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mEventHandler.removeCallbacksAndMessages(null); 10449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native void native_reset(); 10479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 10499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns the maximum absolute amplitude that was sampled since the last 10509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * call to this method. Call this only after the setAudioSource(). 10519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 10529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the maximum absolute amplitude measured since the last call, or 10539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 0 when called for the first time 10549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @throws IllegalStateException if it is called before 10559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the audio source has been set. 10569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native int getMaxAmplitude() throws IllegalStateException; 10589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /* Do not change this value without updating its counterpart 1060a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong * in include/media/mediarecorder.h or mediaplayer.h! 10619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** Unspecified media recorder error. 10639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @see android.media.MediaRecorder.OnErrorListener 10649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public static final int MEDIA_RECORDER_ERROR_UNKNOWN = 1; 1066a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong /** Media server died. In this case, the application must release the 1067a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong * MediaRecorder object and instantiate a new one. 1068a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong * @see android.media.MediaRecorder.OnErrorListener 1069a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong */ 1070a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong public static final int MEDIA_ERROR_SERVER_DIED = 100; 10719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 10739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Interface definition for a callback to be invoked when an error 10749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * occurs while recording. 10759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public interface OnErrorListener 10779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 10789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 10799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Called when an error occurs while recording. 10802bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang * 10819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param mr the MediaRecorder that encountered the error 10829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param what the type of error that has occurred: 10839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <ul> 10849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * <li>{@link #MEDIA_RECORDER_ERROR_UNKNOWN} 1085a35379ae984ddb8fe067c4b115fffc5a21e565e1James Dong * <li>{@link #MEDIA_ERROR_SERVER_DIED} 10869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * </ul> 10879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param extra an extra code, specific to the error type 10889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project void onError(MediaRecorder mr, int what, int extra); 10909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 10919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 10929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 10939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Register a callback to be invoked when an error occurs while 10949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * recording. 10959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 10969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param l the callback that will be run 10979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 10989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setOnErrorListener(OnErrorListener l) 10999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 11009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnErrorListener = l; 11019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 11029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1103ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /* Do not change these values without updating their counterparts 1104ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * in include/media/mediarecorder.h! 1105ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 11066f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih /** Unspecified media recorder info. 1107ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * @see android.media.MediaRecorder.OnInfoListener 1108ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 1109ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project public static final int MEDIA_RECORDER_INFO_UNKNOWN = 1; 1110ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /** A maximum duration had been setup and has now been reached. 1111ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * @see android.media.MediaRecorder.OnInfoListener 1112ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 1113ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project public static final int MEDIA_RECORDER_INFO_MAX_DURATION_REACHED = 800; 1114105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project /** A maximum filesize had been setup and has now been reached. 1115e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * Note: This event will not be sent if application already set 1116e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * next output file through {@link #setNextOutputFile}. 1117105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * @see android.media.MediaRecorder.OnInfoListener 1118105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project */ 1119105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project public static final int MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED = 801; 1120e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang /** A maximum filesize had been setup and current recorded file size 1121e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * has reached 90% of the limit. This is sent once per file upon 1122e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * reaching/passing the 90% limit. To continue the recording, applicaiton 1123e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * should use {@link #setNextOutputFile} to set the next output file. 1124e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * Otherwise, recording will stop when reaching maximum file size. 1125e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @see android.media.MediaRecorder.OnInfoListener 1126e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang */ 1127e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang public static final int MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING = 802; 1128e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang /** A maximum filesize had been reached and MediaRecorder has switched 1129e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * output to a new file set by application {@link #setNextOutputFile}. 1130e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * For best practice, application should use this event to keep track 1131e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * of whether the file previously set has been used or not. 1132e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang * @see android.media.MediaRecorder.OnInfoListener 1133e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang */ 1134e176ee1222931d67aaea0a3df96262728cc31031Hangyu Kuang public static final int MEDIA_RECORDER_INFO_NEXT_OUTPUT_FILE_STARTED = 803; 1135ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 11369e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** informational events for individual tracks, for testing purpose. 11379e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * The track informational event usually contains two parts in the ext1 11389e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * arg of the onInfo() callback: bit 31-28 contains the track id; and 11399e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * the rest of the 28 bits contains the informational event defined here. 11409e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * For example, ext1 = (1 << 28 | MEDIA_RECORDER_TRACK_INFO_TYPE) if the 11419e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * track id is 1 for informational event MEDIA_RECORDER_TRACK_INFO_TYPE; 11429e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * while ext1 = (0 << 28 | MEDIA_RECORDER_TRACK_INFO_TYPE) if the track 11439e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * id is 0 for informational event MEDIA_RECORDER_TRACK_INFO_TYPE. The 11449e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * application should extract the track id and the type of informational 11459e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * event from ext1, accordingly. 11469e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * 11479e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * FIXME: 11489e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * Please update the comment for onInfo also when these 11499e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * events are unhidden so that application knows how to extract the track 11509e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * id and the informational event type from onInfo callback. 11519e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * 11529e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11539e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11549e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_LIST_START = 1000; 11559e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Signal the completion of the track for the recording session. 11569e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11579e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11589e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_COMPLETION_STATUS = 1000; 11599e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Indicate the recording progress in time (ms) during recording. 11609e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11619e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11629e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_PROGRESS_IN_TIME = 1001; 11639e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Indicate the track type: 0 for Audio and 1 for Video. 11649e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11659e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11669e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_TYPE = 1002; 11679e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the track duration information. 11689e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11699e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11709e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_DURATION_MS = 1003; 11719e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the max chunk duration in time (ms) for the given track. 11729e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11739e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11749e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_MAX_CHUNK_DUR_MS = 1004; 11759e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the total number of recordd frames. 11769e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11779e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11789e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_ENCODED_FRAMES = 1005; 11799e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the max spacing between neighboring chunks for the given track. 11809e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11819e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11829e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INTER_CHUNK_TIME_MS = 1006; 11839e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the elapsed time measuring from the start of the recording 11849e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * till the first output frame of the given track is received, excluding 11859e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * any intentional start time offset of a recording session for the 11869e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * purpose of eliminating the recording sound in the recorded file. 11879e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11889e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11899e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_INITIAL_DELAY_MS = 1007; 11909e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** Provide the start time difference (delay) betweeen this track and 11919e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * the start of the movie. 11929e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 11939e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 11949e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_START_OFFSET_MS = 1008; 11950f32fb3ecfdfaa03acf880a356629d43da3fe2feJames Dong /** Provide the total number of data (in kilo-bytes) encoded. 11960f32fb3ecfdfaa03acf880a356629d43da3fe2feJames Dong * {@hide} 11970f32fb3ecfdfaa03acf880a356629d43da3fe2feJames Dong */ 11980f32fb3ecfdfaa03acf880a356629d43da3fe2feJames Dong public static final int MEDIA_RECORDER_TRACK_INFO_DATA_KBYTES = 1009; 11999e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /** 12009e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong * {@hide} 12019e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong */ 12029e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong public static final int MEDIA_RECORDER_TRACK_INFO_LIST_END = 2000; 12039e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong 12049e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong 1205ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /** 12066f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * Interface definition of a callback to be invoked to communicate some 12076f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * info and/or warning about the recording. 1208ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 1209ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project public interface OnInfoListener 1210ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project { 1211ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /** 12126f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * Called to indicate an info or a warning during recording. 12132bcda90c0234f67f210a96f195b355493ca7d1ffJianhong Jiang * 12146f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * @param mr the MediaRecorder the info pertains to 12156f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * @param what the type of info or warning that has occurred 1216ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * <ul> 1217ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * <li>{@link #MEDIA_RECORDER_INFO_UNKNOWN} 1218105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * <li>{@link #MEDIA_RECORDER_INFO_MAX_DURATION_REACHED} 1219105925376f8d0f6b318c9938c7b83ef7fef094daThe Android Open Source Project * <li>{@link #MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED} 1220ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * </ul> 12216f5be322d2f25b2c8a90c0f2480bc8156d5452a7Robert Shih * @param extra an extra code, specific to the info type 1222ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 1223ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project void onInfo(MediaRecorder mr, int what, int extra); 1224ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project } 1225ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 1226ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /** 1227ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * Register a callback to be invoked when an informational event occurs while 1228ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * recording. 1229ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * 1230ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project * @param listener the callback that will be run 1231ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project */ 1232ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project public void setOnInfoListener(OnInfoListener listener) 1233ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project { 1234ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project mOnInfoListener = listener; 1235ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project } 1236ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 12379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private class EventHandler extends Handler 12389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 12399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private MediaRecorder mMediaRecorder; 12409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public EventHandler(MediaRecorder mr, Looper looper) { 12429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project super(looper); 12439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mMediaRecorder = mr; 12449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1246ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project /* Do not change these values without updating their counterparts 12479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * in include/media/mediarecorder.h! 12489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 12499e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_EVENT_LIST_START = 1; 12509e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_EVENT_ERROR = 1; 12519e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_EVENT_INFO = 2; 12529e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_EVENT_LIST_END = 99; 12539e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong 12549e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong /* Events related to individual tracks */ 12559e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_TRACK_EVENT_LIST_START = 100; 12569e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_TRACK_EVENT_ERROR = 100; 12579e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_TRACK_EVENT_INFO = 101; 12589e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong private static final int MEDIA_RECORDER_TRACK_EVENT_LIST_END = 1000; 12599e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong 1260fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin private static final int MEDIA_RECORDER_AUDIO_ROUTING_CHANGED = 10000; 12619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @Override 12639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void handleMessage(Message msg) { 12649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mMediaRecorder.mNativeContext == 0) { 12659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.w(TAG, "mediarecorder went away with unhandled events"); 12669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 12679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project switch(msg.what) { 12699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project case MEDIA_RECORDER_EVENT_ERROR: 12709e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong case MEDIA_RECORDER_TRACK_EVENT_ERROR: 12719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mOnErrorListener != null) 12729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mOnErrorListener.onError(mMediaRecorder, msg.arg1, msg.arg2); 12739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 12749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 12759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1276ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project case MEDIA_RECORDER_EVENT_INFO: 12779e836a7d2e4bb04a9c85dcb6b1f0cef50d5fd2e1James Dong case MEDIA_RECORDER_TRACK_EVENT_INFO: 1278ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project if (mOnInfoListener != null) 1279ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project mOnInfoListener.onInfo(mMediaRecorder, msg.arg1, msg.arg2); 1280ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 1281ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project return; 1282ba87e3e6c985e7175152993b5efcc7dd2f0e1c93The Android Open Source Project 1283fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin case MEDIA_RECORDER_AUDIO_ROUTING_CHANGED: 1284fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin AudioManager.resetAudioPortGeneration(); 1285fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin synchronized (mRoutingChangeListeners) { 1286fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin for (NativeRoutingEventHandlerDelegate delegate 1287fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin : mRoutingChangeListeners.values()) { 1288fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin delegate.notifyClient(); 1289fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1290fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1291fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin return; 1292fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin 12939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project default: 12949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Log.e(TAG, "Unknown message type " + msg.what); 12959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 12969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 12999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1300fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin //-------------------------------------------------------------------------- 1301fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin // Explicit Routing 1302fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin //-------------------- 1303fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin private AudioDeviceInfo mPreferredDevice = null; 1304fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin 1305fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin /** 1306fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * Specifies an audio device (via an {@link AudioDeviceInfo} object) to route 1307fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * the input from this MediaRecorder. 1308fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * @param deviceInfo The {@link AudioDeviceInfo} specifying the audio source. 1309fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * If deviceInfo is null, default routing is restored. 1310fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * @return true if succesful, false if the specified {@link AudioDeviceInfo} is non-null and 1311fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * does not correspond to a valid audio input device. 1312fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin */ 1313fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin @Override 1314fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin public boolean setPreferredDevice(AudioDeviceInfo deviceInfo) { 1315fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin if (deviceInfo != null && !deviceInfo.isSource()) { 1316fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin return false; 1317fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1318fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin int preferredDeviceId = deviceInfo != null ? deviceInfo.getId() : 0; 1319fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin boolean status = native_setInputDevice(preferredDeviceId); 1320fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin if (status == true) { 1321fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin synchronized (this) { 1322fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin mPreferredDevice = deviceInfo; 1323fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1324fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1325fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin return status; 1326fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1327fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin 1328fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin /** 1329fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * Returns the selected input device specified by {@link #setPreferredDevice}. Note that this 1330fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * is not guaranteed to correspond to the actual device being used for recording. 1331fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin */ 1332fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin @Override 1333fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin public AudioDeviceInfo getPreferredDevice() { 1334fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin synchronized (this) { 1335fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin return mPreferredDevice; 1336fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1337fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1338fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin 1339fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin /** 1340fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * Returns an {@link AudioDeviceInfo} identifying the current routing of this MediaRecorder 1341fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * Note: The query is only valid if the MediaRecorder is currently recording. 1342fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * If the recorder is not recording, the returned device can be null or correspond to previously 1343fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * selected device when the recorder was last active. 1344fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin */ 1345fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin @Override 1346fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin public AudioDeviceInfo getRoutedDevice() { 1347fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin int deviceId = native_getRoutedDeviceId(); 1348fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin if (deviceId == 0) { 1349fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin return null; 1350fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1351fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin AudioDeviceInfo[] devices = 1352fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin AudioManager.getDevicesStatic(AudioManager.GET_DEVICES_INPUTS); 1353fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin for (int i = 0; i < devices.length; i++) { 1354fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin if (devices[i].getId() == deviceId) { 1355fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin return devices[i]; 1356fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1357fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1358fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin return null; 1359fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1360fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin 1361fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin /* 1362fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * Call BEFORE adding a routing callback handler or AFTER removing a routing callback handler. 1363fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin */ 136457d03914a1d5680cfe0727c15a3a82e4dfeb0adeAndreas Gampe @GuardedBy("mRoutingChangeListeners") 1365fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin private void enableNativeRoutingCallbacksLocked(boolean enabled) { 1366fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin if (mRoutingChangeListeners.size() == 0) { 1367fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin native_enableDeviceCallback(enabled); 1368fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1369fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1370fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin 1371fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin /** 1372fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * The list of AudioRouting.OnRoutingChangedListener interfaces added (with 1373fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * {@link #addOnRoutingChangedListener(android.media.AudioRouting.OnRoutingChangedListener, Handler)} 1374fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * by an app to receive (re)routing notifications. 1375fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin */ 1376fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin @GuardedBy("mRoutingChangeListeners") 1377fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin private ArrayMap<AudioRouting.OnRoutingChangedListener, 1378fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin NativeRoutingEventHandlerDelegate> mRoutingChangeListeners = new ArrayMap<>(); 1379fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin 1380fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin /** 1381fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * Adds an {@link AudioRouting.OnRoutingChangedListener} to receive notifications of routing 1382fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * changes on this MediaRecorder. 1383fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * @param listener The {@link AudioRouting.OnRoutingChangedListener} interface to receive 1384fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * notifications of rerouting events. 1385fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * @param handler Specifies the {@link Handler} object for the thread on which to execute 1386fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * the callback. If <code>null</code>, the handler on the main looper will be used. 1387fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin */ 1388fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin @Override 1389fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin public void addOnRoutingChangedListener(AudioRouting.OnRoutingChangedListener listener, 1390fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin Handler handler) { 1391fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin synchronized (mRoutingChangeListeners) { 1392fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin if (listener != null && !mRoutingChangeListeners.containsKey(listener)) { 1393fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin enableNativeRoutingCallbacksLocked(true); 1394fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin mRoutingChangeListeners.put( 13950b9fa5199231e48621d1f73689d572a7a31751b5jiabin listener, new NativeRoutingEventHandlerDelegate(this, listener, 13960b9fa5199231e48621d1f73689d572a7a31751b5jiabin handler != null ? handler : mEventHandler)); 1397fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1398fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1399fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1400fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin 1401fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin /** 1402fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * Removes an {@link AudioRouting.OnRoutingChangedListener} which has been previously added 1403fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * to receive rerouting notifications. 1404fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * @param listener The previously added {@link AudioRouting.OnRoutingChangedListener} interface 1405fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin * to remove. 1406fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin */ 1407fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin @Override 1408fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin public void removeOnRoutingChangedListener(AudioRouting.OnRoutingChangedListener listener) { 1409fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin synchronized (mRoutingChangeListeners) { 1410fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin if (mRoutingChangeListeners.containsKey(listener)) { 1411fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin mRoutingChangeListeners.remove(listener); 1412fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin enableNativeRoutingCallbacksLocked(false); 1413fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1414fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1415fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin } 1416fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin 1417fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin private native final boolean native_setInputDevice(int deviceId); 1418fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin private native final int native_getRoutedDeviceId(); 1419fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin private native final void native_enableDeviceCallback(boolean enabled); 1420fe3e6024ed03de26e44df9d366f30a09f00485c8jiabin 1421589f6a299ed464cf70a953992b5013d8b275099cjiabin //-------------------------------------------------------------------------- 1422589f6a299ed464cf70a953992b5013d8b275099cjiabin // Microphone information 1423589f6a299ed464cf70a953992b5013d8b275099cjiabin //-------------------- 1424589f6a299ed464cf70a953992b5013d8b275099cjiabin /** 1425589f6a299ed464cf70a953992b5013d8b275099cjiabin * Return A lists of {@link MicrophoneInfo} representing the active microphones. 1426589f6a299ed464cf70a953992b5013d8b275099cjiabin * By querying channel mapping for each active microphone, developer can know how 1427589f6a299ed464cf70a953992b5013d8b275099cjiabin * the microphone is used by each channels or a capture stream. 1428589f6a299ed464cf70a953992b5013d8b275099cjiabin * 1429589f6a299ed464cf70a953992b5013d8b275099cjiabin * @return a lists of {@link MicrophoneInfo} representing the active microphones 1430589f6a299ed464cf70a953992b5013d8b275099cjiabin * @throws IOException if an error occurs 1431589f6a299ed464cf70a953992b5013d8b275099cjiabin */ 1432589f6a299ed464cf70a953992b5013d8b275099cjiabin public List<MicrophoneInfo> getActiveMicrophones() throws IOException { 1433589f6a299ed464cf70a953992b5013d8b275099cjiabin ArrayList<MicrophoneInfo> activeMicrophones = new ArrayList<>(); 1434589f6a299ed464cf70a953992b5013d8b275099cjiabin int status = native_getActiveMicrophones(activeMicrophones); 1435589f6a299ed464cf70a953992b5013d8b275099cjiabin if (status != AudioManager.SUCCESS) { 1436a26a76230f0dc5b70f8b26e997240af2e9c17a2bjiabin if (status != AudioManager.ERROR_INVALID_OPERATION) { 1437a26a76230f0dc5b70f8b26e997240af2e9c17a2bjiabin Log.e(TAG, "getActiveMicrophones failed:" + status); 1438a26a76230f0dc5b70f8b26e997240af2e9c17a2bjiabin } 1439a26a76230f0dc5b70f8b26e997240af2e9c17a2bjiabin Log.i(TAG, "getActiveMicrophones failed, fallback on routed device info"); 1440589f6a299ed464cf70a953992b5013d8b275099cjiabin } 1441589f6a299ed464cf70a953992b5013d8b275099cjiabin AudioManager.setPortIdForMicrophones(activeMicrophones); 1442589a236acfeaec27bc3465b69ca9c701a2f65810jiabin 1443589a236acfeaec27bc3465b69ca9c701a2f65810jiabin // Use routed device when there is not information returned by hal. 1444589a236acfeaec27bc3465b69ca9c701a2f65810jiabin if (activeMicrophones.size() == 0) { 1445589a236acfeaec27bc3465b69ca9c701a2f65810jiabin AudioDeviceInfo device = getRoutedDevice(); 1446589a236acfeaec27bc3465b69ca9c701a2f65810jiabin if (device != null) { 1447589a236acfeaec27bc3465b69ca9c701a2f65810jiabin MicrophoneInfo microphone = AudioManager.microphoneInfoFromAudioDeviceInfo(device); 1448589a236acfeaec27bc3465b69ca9c701a2f65810jiabin ArrayList<Pair<Integer, Integer>> channelMapping = new ArrayList<>(); 1449589a236acfeaec27bc3465b69ca9c701a2f65810jiabin for (int i = 0; i < mChannelCount; i++) { 1450589a236acfeaec27bc3465b69ca9c701a2f65810jiabin channelMapping.add(new Pair(i, MicrophoneInfo.CHANNEL_MAPPING_DIRECT)); 1451589a236acfeaec27bc3465b69ca9c701a2f65810jiabin } 1452589a236acfeaec27bc3465b69ca9c701a2f65810jiabin microphone.setChannelMapping(channelMapping); 1453589a236acfeaec27bc3465b69ca9c701a2f65810jiabin activeMicrophones.add(microphone); 1454589a236acfeaec27bc3465b69ca9c701a2f65810jiabin } 1455589a236acfeaec27bc3465b69ca9c701a2f65810jiabin } 1456589f6a299ed464cf70a953992b5013d8b275099cjiabin return activeMicrophones; 1457589f6a299ed464cf70a953992b5013d8b275099cjiabin } 1458589f6a299ed464cf70a953992b5013d8b275099cjiabin 1459589f6a299ed464cf70a953992b5013d8b275099cjiabin private native final int native_getActiveMicrophones( 1460589f6a299ed464cf70a953992b5013d8b275099cjiabin ArrayList<MicrophoneInfo> activeMicrophones); 1461589f6a299ed464cf70a953992b5013d8b275099cjiabin 14629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 14639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Called from native code when an interesting event happens. This method 14649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * just uses the EventHandler system to post the event back to the main app thread. 14659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * We use a weak reference to the original MediaRecorder object so that the native 14669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * code is safe from the object disappearing from underneath it. (This is 14679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the cookie passed to native_setup().) 14689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 14699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private static void postEventFromNative(Object mediarecorder_ref, 14709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project int what, int arg1, int arg2, Object obj) 14719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project { 14729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project MediaRecorder mr = (MediaRecorder)((WeakReference)mediarecorder_ref).get(); 14739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mr == null) { 14749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return; 14759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 14769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 14779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (mr.mEventHandler != null) { 14789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Message m = mr.mEventHandler.obtainMessage(what, arg1, arg2, obj); 14799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mr.mEventHandler.sendMessage(m); 14809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 14819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 14829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 14839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 14849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Releases resources associated with this MediaRecorder object. 14859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * It is good practice to call this method when you're done 148689ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * using the MediaRecorder. In particular, whenever an Activity 148789ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * of an application is paused (its onPause() method is called), 148889ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * or stopped (its onStop() method is called), this method should be 148989ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * invoked to release the MediaRecorder object, unless the application 149089ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * has a special need to keep the object around. In addition to 149189ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * unnecessary resources (such as memory and instances of codecs) 149289ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * being held, failure to call this method immediately if a 149389ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * MediaRecorder object is no longer needed may also lead to 149489ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * continuous battery consumption for mobile devices, and recording 149589ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * failure for other applications if no multiple instances of the 149689ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * same codec are supported on a device. Even if multiple instances 149789ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * of the same codec are supported, some performance degradation 149889ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * may be expected when unnecessary multiple instances are used 149989ca6983eb2be21848f5ac884a2c118f152c83e6James Dong * at the same time. 15009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 15019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public native void release(); 15029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 15034935d05eaa306cef88cf0ab13eca386f270409ecMarco Nelissen private static native final void native_init(); 15044935d05eaa306cef88cf0ab13eca386f270409ecMarco Nelissen 1505788717ca599c714d58b2cb5deea1d37b4a711c07Eino-Ville Talvala private native final void native_setup(Object mediarecorder_this, 1506fa5ecdc4ac6d7a8db2bb9e4a6a60a3189025df30Svet Ganov String clientName, String opPackageName) throws IllegalStateException; 15079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 15089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project private native final void native_finalize(); 15099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 15100fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong private native void setParameter(String nameValuePair); 15110fc6bc4cac6391f048f0f2748b3e979effe0924bJames Dong 1512b0bd62f96cd81f5209ea01e4f484f5b35a389cc0Ray Essick /** 1513f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick * Return Metrics data about the current Mediarecorder instance. 1514b0bd62f96cd81f5209ea01e4f484f5b35a389cc0Ray Essick * 151510353e36018224b86ef2918d1d68107459d445cfRay Essick * @return a {@link PersistableBundle} containing the set of attributes and values 1516f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick * available for the media being generated by this instance of 1517f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick * MediaRecorder. 151810353e36018224b86ef2918d1d68107459d445cfRay Essick * The attributes are descibed in {@link MetricsConstants}. 1519b0bd62f96cd81f5209ea01e4f484f5b35a389cc0Ray Essick * 1520f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick * Additional vendor-specific fields may also be present in 1521f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick * the return value. 1522f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick */ 152310353e36018224b86ef2918d1d68107459d445cfRay Essick public PersistableBundle getMetrics() { 152410353e36018224b86ef2918d1d68107459d445cfRay Essick PersistableBundle bundle = native_getMetrics(); 152510353e36018224b86ef2918d1d68107459d445cfRay Essick return bundle; 1526f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick } 1527f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick 152810353e36018224b86ef2918d1d68107459d445cfRay Essick private native PersistableBundle native_getMetrics(); 1529b0bd62f96cd81f5209ea01e4f484f5b35a389cc0Ray Essick 15309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project @Override 15319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project protected void finalize() { native_finalize(); } 153210353e36018224b86ef2918d1d68107459d445cfRay Essick 153310353e36018224b86ef2918d1d68107459d445cfRay Essick public final static class MetricsConstants 153410353e36018224b86ef2918d1d68107459d445cfRay Essick { 153510353e36018224b86ef2918d1d68107459d445cfRay Essick private MetricsConstants() {} 153610353e36018224b86ef2918d1d68107459d445cfRay Essick 153710353e36018224b86ef2918d1d68107459d445cfRay Essick /** 153810353e36018224b86ef2918d1d68107459d445cfRay Essick * Key to extract the audio bitrate 153910353e36018224b86ef2918d1d68107459d445cfRay Essick * from the {@link MediaRecorder#getMetrics} return. 154010353e36018224b86ef2918d1d68107459d445cfRay Essick * The value is an integer. 154110353e36018224b86ef2918d1d68107459d445cfRay Essick */ 154210353e36018224b86ef2918d1d68107459d445cfRay Essick public static final String AUDIO_BITRATE = "android.media.mediarecorder.audio-bitrate"; 154310353e36018224b86ef2918d1d68107459d445cfRay Essick 154410353e36018224b86ef2918d1d68107459d445cfRay Essick /** 154510353e36018224b86ef2918d1d68107459d445cfRay Essick * Key to extract the number of audio channels 154610353e36018224b86ef2918d1d68107459d445cfRay Essick * from the {@link MediaRecorder#getMetrics} return. 154710353e36018224b86ef2918d1d68107459d445cfRay Essick * The value is an integer. 154810353e36018224b86ef2918d1d68107459d445cfRay Essick */ 154910353e36018224b86ef2918d1d68107459d445cfRay Essick public static final String AUDIO_CHANNELS = "android.media.mediarecorder.audio-channels"; 155010353e36018224b86ef2918d1d68107459d445cfRay Essick 155110353e36018224b86ef2918d1d68107459d445cfRay Essick /** 155210353e36018224b86ef2918d1d68107459d445cfRay Essick * Key to extract the audio samplerate 155310353e36018224b86ef2918d1d68107459d445cfRay Essick * from the {@link MediaRecorder#getMetrics} return. 155410353e36018224b86ef2918d1d68107459d445cfRay Essick * The value is an integer. 155510353e36018224b86ef2918d1d68107459d445cfRay Essick */ 155610353e36018224b86ef2918d1d68107459d445cfRay Essick public static final String AUDIO_SAMPLERATE = "android.media.mediarecorder.audio-samplerate"; 155710353e36018224b86ef2918d1d68107459d445cfRay Essick 155810353e36018224b86ef2918d1d68107459d445cfRay Essick /** 155910353e36018224b86ef2918d1d68107459d445cfRay Essick * Key to extract the audio timescale 156010353e36018224b86ef2918d1d68107459d445cfRay Essick * from the {@link MediaRecorder#getMetrics} return. 156110353e36018224b86ef2918d1d68107459d445cfRay Essick * The value is an integer. 156210353e36018224b86ef2918d1d68107459d445cfRay Essick */ 156310353e36018224b86ef2918d1d68107459d445cfRay Essick public static final String AUDIO_TIMESCALE = "android.media.mediarecorder.audio-timescale"; 156410353e36018224b86ef2918d1d68107459d445cfRay Essick 156510353e36018224b86ef2918d1d68107459d445cfRay Essick /** 156610353e36018224b86ef2918d1d68107459d445cfRay Essick * Key to extract the video capture frame rate 156710353e36018224b86ef2918d1d68107459d445cfRay Essick * from the {@link MediaRecorder#getMetrics} return. 156810353e36018224b86ef2918d1d68107459d445cfRay Essick * The value is a double. 156910353e36018224b86ef2918d1d68107459d445cfRay Essick */ 157010353e36018224b86ef2918d1d68107459d445cfRay Essick public static final String CAPTURE_FPS = "android.media.mediarecorder.capture-fps"; 157110353e36018224b86ef2918d1d68107459d445cfRay Essick 157210353e36018224b86ef2918d1d68107459d445cfRay Essick /** 157310353e36018224b86ef2918d1d68107459d445cfRay Essick * Key to extract the video capture framerate enable value 157410353e36018224b86ef2918d1d68107459d445cfRay Essick * from the {@link MediaRecorder#getMetrics} return. 157510353e36018224b86ef2918d1d68107459d445cfRay Essick * The value is an integer. 157610353e36018224b86ef2918d1d68107459d445cfRay Essick */ 157710353e36018224b86ef2918d1d68107459d445cfRay Essick public static final String CAPTURE_FPS_ENABLE = "android.media.mediarecorder.capture-fpsenable"; 157810353e36018224b86ef2918d1d68107459d445cfRay Essick 157910353e36018224b86ef2918d1d68107459d445cfRay Essick /** 158010353e36018224b86ef2918d1d68107459d445cfRay Essick * Key to extract the intended playback frame rate 158110353e36018224b86ef2918d1d68107459d445cfRay Essick * from the {@link MediaRecorder#getMetrics} return. 158210353e36018224b86ef2918d1d68107459d445cfRay Essick * The value is an integer. 158310353e36018224b86ef2918d1d68107459d445cfRay Essick */ 158410353e36018224b86ef2918d1d68107459d445cfRay Essick public static final String FRAMERATE = "android.media.mediarecorder.frame-rate"; 158510353e36018224b86ef2918d1d68107459d445cfRay Essick 158610353e36018224b86ef2918d1d68107459d445cfRay Essick /** 158710353e36018224b86ef2918d1d68107459d445cfRay Essick * Key to extract the height (in pixels) of the captured video 158810353e36018224b86ef2918d1d68107459d445cfRay Essick * from the {@link MediaRecorder#getMetrics} return. 158910353e36018224b86ef2918d1d68107459d445cfRay Essick * The value is an integer. 159010353e36018224b86ef2918d1d68107459d445cfRay Essick */ 159110353e36018224b86ef2918d1d68107459d445cfRay Essick public static final String HEIGHT = "android.media.mediarecorder.height"; 159210353e36018224b86ef2918d1d68107459d445cfRay Essick 159310353e36018224b86ef2918d1d68107459d445cfRay Essick /** 159410353e36018224b86ef2918d1d68107459d445cfRay Essick * Key to extract the recorded movies time units 159510353e36018224b86ef2918d1d68107459d445cfRay Essick * from the {@link MediaRecorder#getMetrics} return. 159610353e36018224b86ef2918d1d68107459d445cfRay Essick * The value is an integer. 159710353e36018224b86ef2918d1d68107459d445cfRay Essick * A value of 1000 indicates that the movie's timing is in milliseconds. 159810353e36018224b86ef2918d1d68107459d445cfRay Essick */ 159910353e36018224b86ef2918d1d68107459d445cfRay Essick public static final String MOVIE_TIMESCALE = "android.media.mediarecorder.movie-timescale"; 160010353e36018224b86ef2918d1d68107459d445cfRay Essick 160110353e36018224b86ef2918d1d68107459d445cfRay Essick /** 160210353e36018224b86ef2918d1d68107459d445cfRay Essick * Key to extract the rotation (in degrees) to properly orient the video 160310353e36018224b86ef2918d1d68107459d445cfRay Essick * from the {@link MediaRecorder#getMetrics} return. 160410353e36018224b86ef2918d1d68107459d445cfRay Essick * The value is an integer. 160510353e36018224b86ef2918d1d68107459d445cfRay Essick */ 160610353e36018224b86ef2918d1d68107459d445cfRay Essick public static final String ROTATION = "android.media.mediarecorder.rotation"; 160710353e36018224b86ef2918d1d68107459d445cfRay Essick 160810353e36018224b86ef2918d1d68107459d445cfRay Essick /** 160910353e36018224b86ef2918d1d68107459d445cfRay Essick * Key to extract the video bitrate from being used 161010353e36018224b86ef2918d1d68107459d445cfRay Essick * from the {@link MediaRecorder#getMetrics} return. 161110353e36018224b86ef2918d1d68107459d445cfRay Essick * The value is an integer. 161210353e36018224b86ef2918d1d68107459d445cfRay Essick */ 161310353e36018224b86ef2918d1d68107459d445cfRay Essick public static final String VIDEO_BITRATE = "android.media.mediarecorder.video-bitrate"; 161410353e36018224b86ef2918d1d68107459d445cfRay Essick 161510353e36018224b86ef2918d1d68107459d445cfRay Essick /** 161610353e36018224b86ef2918d1d68107459d445cfRay Essick * Key to extract the value for how often video iframes are generated 161710353e36018224b86ef2918d1d68107459d445cfRay Essick * from the {@link MediaRecorder#getMetrics} return. 161810353e36018224b86ef2918d1d68107459d445cfRay Essick * The value is an integer. 161910353e36018224b86ef2918d1d68107459d445cfRay Essick */ 162010353e36018224b86ef2918d1d68107459d445cfRay Essick public static final String VIDEO_IFRAME_INTERVAL = "android.media.mediarecorder.video-iframe-interval"; 162110353e36018224b86ef2918d1d68107459d445cfRay Essick 162210353e36018224b86ef2918d1d68107459d445cfRay Essick /** 162310353e36018224b86ef2918d1d68107459d445cfRay Essick * Key to extract the video encoding level 162410353e36018224b86ef2918d1d68107459d445cfRay Essick * from the {@link MediaRecorder#getMetrics} return. 162510353e36018224b86ef2918d1d68107459d445cfRay Essick * The value is an integer. 162610353e36018224b86ef2918d1d68107459d445cfRay Essick */ 162710353e36018224b86ef2918d1d68107459d445cfRay Essick public static final String VIDEO_LEVEL = "android.media.mediarecorder.video-encoder-level"; 162810353e36018224b86ef2918d1d68107459d445cfRay Essick 162910353e36018224b86ef2918d1d68107459d445cfRay Essick /** 163010353e36018224b86ef2918d1d68107459d445cfRay Essick * Key to extract the video encoding profile 163110353e36018224b86ef2918d1d68107459d445cfRay Essick * from the {@link MediaRecorder#getMetrics} return. 163210353e36018224b86ef2918d1d68107459d445cfRay Essick * The value is an integer. 163310353e36018224b86ef2918d1d68107459d445cfRay Essick */ 163410353e36018224b86ef2918d1d68107459d445cfRay Essick public static final String VIDEO_PROFILE = "android.media.mediarecorder.video-encoder-profile"; 163510353e36018224b86ef2918d1d68107459d445cfRay Essick 163610353e36018224b86ef2918d1d68107459d445cfRay Essick /** 163710353e36018224b86ef2918d1d68107459d445cfRay Essick * Key to extract the recorded video time units 163810353e36018224b86ef2918d1d68107459d445cfRay Essick * from the {@link MediaRecorder#getMetrics} return. 163910353e36018224b86ef2918d1d68107459d445cfRay Essick * The value is an integer. 164010353e36018224b86ef2918d1d68107459d445cfRay Essick * A value of 1000 indicates that the video's timing is in milliseconds. 164110353e36018224b86ef2918d1d68107459d445cfRay Essick */ 164210353e36018224b86ef2918d1d68107459d445cfRay Essick public static final String VIDEO_TIMESCALE = "android.media.mediarecorder.video-timescale"; 164310353e36018224b86ef2918d1d68107459d445cfRay Essick 164410353e36018224b86ef2918d1d68107459d445cfRay Essick /** 164510353e36018224b86ef2918d1d68107459d445cfRay Essick * Key to extract the width (in pixels) of the captured video 164610353e36018224b86ef2918d1d68107459d445cfRay Essick * from the {@link MediaRecorder#getMetrics} return. 164710353e36018224b86ef2918d1d68107459d445cfRay Essick * The value is an integer. 164810353e36018224b86ef2918d1d68107459d445cfRay Essick */ 164910353e36018224b86ef2918d1d68107459d445cfRay Essick public static final String WIDTH = "android.media.mediarecorder.width"; 165010353e36018224b86ef2918d1d68107459d445cfRay Essick 165110353e36018224b86ef2918d1d68107459d445cfRay Essick } 16529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 16539ef7fe43c9cd78382d699882e3b3170a50f62653Hangyu Kuang 1654