@independo/capacitor-voice-recorder 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorVoiceRecorder.podspec +17 -0
- package/README.md +232 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/tchvu3/capacitorvoicerecorder/CurrentRecordingStatus.java +7 -0
- package/android/src/main/java/com/tchvu3/capacitorvoicerecorder/CustomMediaRecorder.java +107 -0
- package/android/src/main/java/com/tchvu3/capacitorvoicerecorder/Messages.java +14 -0
- package/android/src/main/java/com/tchvu3/capacitorvoicerecorder/NotSupportedOsVersion.java +3 -0
- package/android/src/main/java/com/tchvu3/capacitorvoicerecorder/RecordData.java +50 -0
- package/android/src/main/java/com/tchvu3/capacitorvoicerecorder/ResponseGenerator.java +37 -0
- package/android/src/main/java/com/tchvu3/capacitorvoicerecorder/VoiceRecorder.java +184 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +246 -0
- package/dist/esm/VoiceRecorderImpl.d.ts +19 -0
- package/dist/esm/VoiceRecorderImpl.js +176 -0
- package/dist/esm/VoiceRecorderImpl.js.map +1 -0
- package/dist/esm/definitions.d.ts +124 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/predefined-web-responses.d.ts +12 -0
- package/dist/esm/predefined-web-responses.js +12 -0
- package/dist/esm/predefined-web-responses.js.map +1 -0
- package/dist/esm/web.d.ts +13 -0
- package/dist/esm/web.js +33 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +232 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +234 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/CurrentRecordingStatus.swift +9 -0
- package/ios/Plugin/CustomMediaRecorder.swift +79 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Messages.swift +15 -0
- package/ios/Plugin/RecordData.swift +17 -0
- package/ios/Plugin/ResponseGenerator.swift +28 -0
- package/ios/Plugin/VoiceRecorder.swift +130 -0
- package/ios/Plugin/VoiceRecorderPlugin.h +10 -0
- package/ios/Plugin/VoiceRecorderPlugin.m +15 -0
- package/package.json +97 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapacitorVoiceRecorder'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '13.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/README.md
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" />
|
|
3
|
+
</p>
|
|
4
|
+
<h3 align="center">Capacitor Voice Recorder</h3>
|
|
5
|
+
<p align="center"><strong><code>tchvu3/capacitor-voice-recorder</code></strong></p>
|
|
6
|
+
<p align="center">Capacitor plugin for simple voice recording (For Capacitor 5)</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<img src="https://img.shields.io/maintenance/yes/2023" />
|
|
10
|
+
<a href="https://www.npmjs.com/package/capacitor-voice-recorder"><img src="https://img.shields.io/npm/l/capacitor-voice-recorder" /></a>
|
|
11
|
+
<br>
|
|
12
|
+
<a href="https://www.npmjs.com/package/capacitor-voice-recorder"><img src="https://img.shields.io/npm/dw/capacitor-voice-recorder" /></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/capacitor-voice-recorder"><img src="https://img.shields.io/npm/v/capacitor-voice-recorder" /></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
## Maintainers
|
|
17
|
+
|
|
18
|
+
| Maintainer | GitHub |
|
|
19
|
+
|--------------|-------------------------------------|
|
|
20
|
+
| Avihu Harush | [tchvu3](https://github.com/tchvu3) |
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
npm install --save capacitor-voice-recorder
|
|
26
|
+
npx cap sync
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
#### ios note
|
|
30
|
+
|
|
31
|
+
Make sure to include the ```NSMicrophoneUsageDescription```
|
|
32
|
+
key, and a corresponding purpose string in your app's Info.plist
|
|
33
|
+
|
|
34
|
+
## Configuration
|
|
35
|
+
|
|
36
|
+
No configuration required for this plugin.
|
|
37
|
+
|
|
38
|
+
## Supported methods
|
|
39
|
+
|
|
40
|
+
| Name | Android | iOS | Web |
|
|
41
|
+
|:--------------------------------|:--------|:----|:----|
|
|
42
|
+
| canDeviceVoiceRecord | ✅ | ✅ | ✅ |
|
|
43
|
+
| requestAudioRecordingPermission | ✅ | ✅ | ✅ |
|
|
44
|
+
| hasAudioRecordingPermission | ✅ | ✅ | ✅ |
|
|
45
|
+
| startRecording | ✅ | ✅ | ✅ |
|
|
46
|
+
| stopRecording | ✅ | ✅ | ✅ |
|
|
47
|
+
| pauseRecording | ✅ | ✅ | ✅ |
|
|
48
|
+
| resumeRecording | ✅ | ✅ | ✅ |
|
|
49
|
+
| getCurrentStatus | ✅ | ✅ | ✅ |
|
|
50
|
+
|
|
51
|
+
## Overview
|
|
52
|
+
|
|
53
|
+
The `capacitor-voice-recorder` plugin allows you to record audio on Android, iOS, and Web platforms. Below is a summary
|
|
54
|
+
of the key methods and how to use them.
|
|
55
|
+
|
|
56
|
+
### Checking Device Capabilities and Permissions
|
|
57
|
+
|
|
58
|
+
#### canDeviceVoiceRecord
|
|
59
|
+
|
|
60
|
+
Checks if the device/browser can record audio.
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
VoiceRecorder.canDeviceVoiceRecord().then((result: GenericResponse) => console.log(result.value));
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
| Return Value | Description |
|
|
67
|
+
|--------------------|----------------------------------------------------------------------------------------|
|
|
68
|
+
| `{ value: true }` | The device/browser can record audio. |
|
|
69
|
+
| `{ value: false }` | The browser cannot record audio. Note: On mobile, it always returns `{ value: true }`. |
|
|
70
|
+
|
|
71
|
+
#### requestAudioRecordingPermission
|
|
72
|
+
|
|
73
|
+
Requests audio recording permission from the user.
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
VoiceRecorder.requestAudioRecordingPermission().then((result: GenericResponse) => console.log(result.value));
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
| Return Value | Description |
|
|
80
|
+
|--------------------|---------------------|
|
|
81
|
+
| `{ value: true }` | Permission granted. |
|
|
82
|
+
| `{ value: false }` | Permission denied. |
|
|
83
|
+
|
|
84
|
+
#### hasAudioRecordingPermission
|
|
85
|
+
|
|
86
|
+
Checks if the audio recording permission has been granted.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
VoiceRecorder.hasAudioRecordingPermission().then((result: GenericResponse) => console.log(result.value));
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
| Return Value | Description |
|
|
93
|
+
|-------------------------------------|------------------------------------|
|
|
94
|
+
| `{ value: true }` | Permission granted. |
|
|
95
|
+
| `{ value: false }` | Permission denied. |
|
|
96
|
+
| Error Code | Description |
|
|
97
|
+
| `COULD_NOT_QUERY_PERMISSION_STATUS` | Failed to query permission status. |
|
|
98
|
+
|
|
99
|
+
### Managing Recording
|
|
100
|
+
|
|
101
|
+
#### startRecording
|
|
102
|
+
|
|
103
|
+
Starts the audio recording.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
VoiceRecorder.startRecording()
|
|
107
|
+
.then((result: GenericResponse) => console.log(result.value))
|
|
108
|
+
.catch(error => console.log(error));
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
| Return Value | Description |
|
|
112
|
+
|-------------------|---------------------------------|
|
|
113
|
+
| `{ value: true }` | Recording started successfully. |
|
|
114
|
+
|
|
115
|
+
| Error Code | Description |
|
|
116
|
+
|------------------------------|------------------------------------------|
|
|
117
|
+
| `MISSING_PERMISSION` | Required permission is missing. |
|
|
118
|
+
| `DEVICE_CANNOT_VOICE_RECORD` | Device/browser cannot record audio. |
|
|
119
|
+
| `ALREADY_RECORDING` | A recording is already in progress. |
|
|
120
|
+
| `MICROPHONE_BEING_USED` | Microphone is being used by another app. |
|
|
121
|
+
| `FAILED_TO_RECORD` | Unknown error occurred during recording. |
|
|
122
|
+
|
|
123
|
+
#### stopRecording
|
|
124
|
+
|
|
125
|
+
Stops the audio recording and returns the recording data.
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
VoiceRecorder.stopRecording()
|
|
129
|
+
.then((result: RecordingData) => console.log(result.value))
|
|
130
|
+
.catch(error => console.log(error));
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
| Return Value | Description |
|
|
134
|
+
|--------------------|------------------------------------------------|
|
|
135
|
+
| `recordDataBase64` | The recorded audio data in Base64 format. |
|
|
136
|
+
| `msDuration` | The duration of the recording in milliseconds. |
|
|
137
|
+
| `mimeType` | The MIME type of the recorded audio. |
|
|
138
|
+
|
|
139
|
+
| Error Code | Description |
|
|
140
|
+
|-----------------------------|------------------------------------------------------|
|
|
141
|
+
| `RECORDING_HAS_NOT_STARTED` | No recording in progress. |
|
|
142
|
+
| `EMPTY_RECORDING` | Recording stopped immediately after starting. |
|
|
143
|
+
| `FAILED_TO_FETCH_RECORDING` | Unknown error occurred while fetching the recording. |
|
|
144
|
+
|
|
145
|
+
#### pauseRecording
|
|
146
|
+
|
|
147
|
+
Pauses the ongoing audio recording.
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
VoiceRecorder.pauseRecording()
|
|
151
|
+
.then((result: GenericResponse) => console.log(result.value))
|
|
152
|
+
.catch(error => console.log(error));
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
| Return Value | Description |
|
|
156
|
+
|--------------------|--------------------------------|
|
|
157
|
+
| `{ value: true }` | Recording paused successfully. |
|
|
158
|
+
| `{ value: false }` | Recording is already paused. |
|
|
159
|
+
|
|
160
|
+
| Error Code | Description |
|
|
161
|
+
|-----------------------------|----------------------------------------------------|
|
|
162
|
+
| `RECORDING_HAS_NOT_STARTED` | No recording in progress. |
|
|
163
|
+
| `NOT_SUPPORTED_OS_VERSION` | Operation not supported on the current OS version. |
|
|
164
|
+
|
|
165
|
+
#### resumeRecording
|
|
166
|
+
|
|
167
|
+
Resumes a paused audio recording.
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
VoiceRecorder.resumeRecording()
|
|
171
|
+
.then((result: GenericResponse) => console.log(result.value))
|
|
172
|
+
.catch(error => console.log(error));
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
| Return Value | Description |
|
|
176
|
+
|--------------------|---------------------------------|
|
|
177
|
+
| `{ value: true }` | Recording resumed successfully. |
|
|
178
|
+
| `{ value: false }` | Recording is already running. |
|
|
179
|
+
|
|
180
|
+
| Error Code | Description |
|
|
181
|
+
|-----------------------------|----------------------------------------------------|
|
|
182
|
+
| `RECORDING_HAS_NOT_STARTED` | No recording in progress. |
|
|
183
|
+
| `NOT_SUPPORTED_OS_VERSION` | Operation not supported on the current OS version. |
|
|
184
|
+
|
|
185
|
+
#### getCurrentStatus
|
|
186
|
+
|
|
187
|
+
Retrieves the current status of the recorder.
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
VoiceRecorder.getCurrentStatus()
|
|
191
|
+
.then((result: CurrentRecordingStatus) => console.log(result.status))
|
|
192
|
+
.catch(error => console.log(error));
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
| Status Code | Description |
|
|
196
|
+
|-------------|------------------------------------------------------|
|
|
197
|
+
| `NONE` | Plugin is idle and waiting to start a new recording. |
|
|
198
|
+
| `RECORDING` | Plugin is currently recording. |
|
|
199
|
+
| `PAUSED` | Recording is paused. |
|
|
200
|
+
|
|
201
|
+
## Format and Mime type
|
|
202
|
+
|
|
203
|
+
The plugin will return the recording in one of several possible formats.
|
|
204
|
+
the format is dependent on the os / web browser that the user uses.
|
|
205
|
+
on android and ios the mime type will be `audio/aac`, while on chrome and firefox it
|
|
206
|
+
will be `audio/webm;codecs=opus` and on safari it will be `audio/mp4`.
|
|
207
|
+
note that these 3 browsers has been tested on. the plugin should still work on
|
|
208
|
+
other browsers, as there is a list of mime types that the plugin checks against the
|
|
209
|
+
user's browser.
|
|
210
|
+
|
|
211
|
+
Note that this fact might cause unexpected behavior in case you'll try to play recordings
|
|
212
|
+
between several devices or browsers - as they not all support the same set of audio formats.
|
|
213
|
+
it is recommended to convert the recordings to a format that all your target devices supports.
|
|
214
|
+
as this plugin focuses on the recording aspect, it does not provide any conversion between formats.
|
|
215
|
+
|
|
216
|
+
## Playback
|
|
217
|
+
|
|
218
|
+
To play the recorded file you can use plain javascript:
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
const base64Sound = '...' // from plugin
|
|
222
|
+
const mimeType = '...' // from plugin
|
|
223
|
+
const audioRef = new Audio(`data:${mimeType};base64,${base64Sound}`)
|
|
224
|
+
audioRef.oncanplaythrough = () => audioRef.play()
|
|
225
|
+
audioRef.load()
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Donation
|
|
229
|
+
|
|
230
|
+
If you enjoy my work and find it useful, feel free to invite me to a cup of coffee :)
|
|
231
|
+
|
|
232
|
+
[](https://www.buymeacoffee.com/tchvu3)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.0.0'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace "com.tchvu3.capacitorvoicerecorder"
|
|
22
|
+
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
package com.tchvu3.capacitorvoicerecorder;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.media.MediaRecorder;
|
|
5
|
+
import android.os.Build;
|
|
6
|
+
import java.io.File;
|
|
7
|
+
import java.io.IOException;
|
|
8
|
+
|
|
9
|
+
public class CustomMediaRecorder {
|
|
10
|
+
|
|
11
|
+
private final Context context;
|
|
12
|
+
private MediaRecorder mediaRecorder;
|
|
13
|
+
private File outputFile;
|
|
14
|
+
private CurrentRecordingStatus currentRecordingStatus = CurrentRecordingStatus.NONE;
|
|
15
|
+
|
|
16
|
+
public CustomMediaRecorder(Context context) throws IOException {
|
|
17
|
+
this.context = context;
|
|
18
|
+
generateMediaRecorder();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private void generateMediaRecorder() throws IOException {
|
|
22
|
+
mediaRecorder = new MediaRecorder();
|
|
23
|
+
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
|
|
24
|
+
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
|
|
25
|
+
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
|
|
26
|
+
mediaRecorder.setAudioEncodingBitRate(96000);
|
|
27
|
+
mediaRecorder.setAudioSamplingRate(44100);
|
|
28
|
+
setRecorderOutputFile();
|
|
29
|
+
mediaRecorder.prepare();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private void setRecorderOutputFile() throws IOException {
|
|
33
|
+
File outputDir = context.getCacheDir();
|
|
34
|
+
outputFile = File.createTempFile("voice_record_temp", ".aac", outputDir);
|
|
35
|
+
outputFile.deleteOnExit();
|
|
36
|
+
mediaRecorder.setOutputFile(outputFile.getAbsolutePath());
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public void startRecording() {
|
|
40
|
+
mediaRecorder.start();
|
|
41
|
+
currentRecordingStatus = CurrentRecordingStatus.RECORDING;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public void stopRecording() {
|
|
45
|
+
mediaRecorder.stop();
|
|
46
|
+
mediaRecorder.release();
|
|
47
|
+
currentRecordingStatus = CurrentRecordingStatus.NONE;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public File getOutputFile() {
|
|
51
|
+
return outputFile;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public boolean pauseRecording() throws NotSupportedOsVersion {
|
|
55
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
|
56
|
+
throw new NotSupportedOsVersion();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (currentRecordingStatus == CurrentRecordingStatus.RECORDING) {
|
|
60
|
+
mediaRecorder.pause();
|
|
61
|
+
currentRecordingStatus = CurrentRecordingStatus.PAUSED;
|
|
62
|
+
return true;
|
|
63
|
+
} else {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public boolean resumeRecording() throws NotSupportedOsVersion {
|
|
69
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
|
70
|
+
throw new NotSupportedOsVersion();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (currentRecordingStatus == CurrentRecordingStatus.PAUSED) {
|
|
74
|
+
mediaRecorder.resume();
|
|
75
|
+
currentRecordingStatus = CurrentRecordingStatus.RECORDING;
|
|
76
|
+
return true;
|
|
77
|
+
} else {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public CurrentRecordingStatus getCurrentStatus() {
|
|
83
|
+
return currentRecordingStatus;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public boolean deleteOutputFile() {
|
|
87
|
+
return outputFile.delete();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public static boolean canPhoneCreateMediaRecorder(Context context) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private static boolean canPhoneCreateMediaRecorderWhileHavingPermission(Context context) {
|
|
95
|
+
CustomMediaRecorder tempMediaRecorder = null;
|
|
96
|
+
try {
|
|
97
|
+
tempMediaRecorder = new CustomMediaRecorder(context);
|
|
98
|
+
tempMediaRecorder.startRecording();
|
|
99
|
+
tempMediaRecorder.stopRecording();
|
|
100
|
+
return true;
|
|
101
|
+
} catch (Exception exp) {
|
|
102
|
+
return exp.getMessage().startsWith("stop failed");
|
|
103
|
+
} finally {
|
|
104
|
+
if (tempMediaRecorder != null) tempMediaRecorder.deleteOutputFile();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
package com.tchvu3.capacitorvoicerecorder;
|
|
2
|
+
|
|
3
|
+
public abstract class Messages {
|
|
4
|
+
|
|
5
|
+
public static final String MISSING_PERMISSION = "MISSING_PERMISSION";
|
|
6
|
+
public static final String CANNOT_RECORD_ON_THIS_PHONE = "CANNOT_RECORD_ON_THIS_PHONE";
|
|
7
|
+
public static final String FAILED_TO_RECORD = "FAILED_TO_RECORD";
|
|
8
|
+
public static final String RECORDING_HAS_NOT_STARTED = "RECORDING_HAS_NOT_STARTED";
|
|
9
|
+
public static final String FAILED_TO_FETCH_RECORDING = "FAILED_TO_FETCH_RECORDING";
|
|
10
|
+
public static final String NOT_SUPPORTED_OS_VERSION = "NOT_SUPPORTED_OS_VERSION";
|
|
11
|
+
public static final String ALREADY_RECORDING = "ALREADY_RECORDING";
|
|
12
|
+
public static final String EMPTY_RECORDING = "EMPTY_RECORDING";
|
|
13
|
+
public static final String MICROPHONE_BEING_USED = "MICROPHONE_BEING_USED";
|
|
14
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
package com.tchvu3.capacitorvoicerecorder;
|
|
2
|
+
|
|
3
|
+
import com.getcapacitor.JSObject;
|
|
4
|
+
|
|
5
|
+
public class RecordData {
|
|
6
|
+
|
|
7
|
+
private String recordDataBase64;
|
|
8
|
+
private String mimeType;
|
|
9
|
+
private int msDuration;
|
|
10
|
+
|
|
11
|
+
public RecordData() {}
|
|
12
|
+
|
|
13
|
+
public RecordData(String recordDataBase64, int msDuration, String mimeType) {
|
|
14
|
+
this.recordDataBase64 = recordDataBase64;
|
|
15
|
+
this.msDuration = msDuration;
|
|
16
|
+
this.mimeType = mimeType;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public String getRecordDataBase64() {
|
|
20
|
+
return recordDataBase64;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public void setRecordDataBase64(String recordDataBase64) {
|
|
24
|
+
this.recordDataBase64 = recordDataBase64;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public int getMsDuration() {
|
|
28
|
+
return msDuration;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public void setMsDuration(int msDuration) {
|
|
32
|
+
this.msDuration = msDuration;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public String getMimeType() {
|
|
36
|
+
return mimeType;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public void setMimeType(String mimeType) {
|
|
40
|
+
this.mimeType = mimeType;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public JSObject toJSObject() {
|
|
44
|
+
JSObject toReturn = new JSObject();
|
|
45
|
+
toReturn.put("recordDataBase64", recordDataBase64);
|
|
46
|
+
toReturn.put("msDuration", msDuration);
|
|
47
|
+
toReturn.put("mimeType", mimeType);
|
|
48
|
+
return toReturn;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
package com.tchvu3.capacitorvoicerecorder;
|
|
2
|
+
|
|
3
|
+
import com.getcapacitor.JSObject;
|
|
4
|
+
|
|
5
|
+
public class ResponseGenerator {
|
|
6
|
+
|
|
7
|
+
private static final String VALUE_RESPONSE_KEY = "value";
|
|
8
|
+
private static final String STATUS_RESPONSE_KEY = "status";
|
|
9
|
+
|
|
10
|
+
public static JSObject fromBoolean(boolean value) {
|
|
11
|
+
return value ? successResponse() : failResponse();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public static JSObject successResponse() {
|
|
15
|
+
JSObject success = new JSObject();
|
|
16
|
+
success.put(VALUE_RESPONSE_KEY, true);
|
|
17
|
+
return success;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public static JSObject failResponse() {
|
|
21
|
+
JSObject success = new JSObject();
|
|
22
|
+
success.put(VALUE_RESPONSE_KEY, false);
|
|
23
|
+
return success;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public static JSObject dataResponse(Object data) {
|
|
27
|
+
JSObject success = new JSObject();
|
|
28
|
+
success.put(VALUE_RESPONSE_KEY, data);
|
|
29
|
+
return success;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public static JSObject statusResponse(CurrentRecordingStatus status) {
|
|
33
|
+
JSObject success = new JSObject();
|
|
34
|
+
success.put(STATUS_RESPONSE_KEY, status.name());
|
|
35
|
+
return success;
|
|
36
|
+
}
|
|
37
|
+
}
|