1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package android.systemui.cts.audiorecorder.mediarecorder;
18 
19 import android.media.MediaRecorder;
20 import android.media.MediaRecorder.AudioSource;
21 import android.systemui.cts.audiorecorder.base.BaseAudioRecorderService;
22 
23 import java.io.File;
24 import java.io.IOException;
25 
26 public class AudioRecorderService extends BaseAudioRecorderService {
27     private MediaRecorder mMediaRecorder = null;
28 
startRecording()29     protected void startRecording() {
30         mMediaRecorder = new MediaRecorder();
31         mMediaRecorder.setAudioSource(AudioSource.MIC);
32         mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
33         mMediaRecorder.setOutputFile(new File(getExternalCacheDir(), "record.3gp"));
34         mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
35 
36         try {
37             mMediaRecorder.prepare();
38         } catch (IOException e) {
39             mMediaRecorder.release();
40             mMediaRecorder = null;
41             return;
42         }
43 
44         mMediaRecorder.start();
45     }
46 
stopRecording()47     protected void stopRecording() {
48         mMediaRecorder.stop();
49         mMediaRecorder.release();
50         mMediaRecorder = null;
51     }
52 
isRecording()53     protected boolean isRecording() {
54         return mMediaRecorder != null;
55     }
56 }
57