Skip to content

Commit 340bc36

Browse files
jquick-axwaysgtcoolguy
authored andcommitted
fix(android): AudioRecorder recording/stopped property handling
Fixes TIMOB-28105
1 parent f8ec672 commit 340bc36

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

android/modules/media/src/java/ti/modules/titanium/media/AudioRecorderProxy.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
importorg.appcelerator.kroll.KrollProxy;
1010
importorg.appcelerator.kroll.annotations.Kroll;
1111
importorg.appcelerator.titanium.TiFileProxy;
12+
importorg.appcelerator.titanium.io.TiBaseFile;
1213
importorg.appcelerator.titanium.io.TiFileFactory;
1314

1415
@Kroll.proxy(creatableInModule = MediaModule.class)
@@ -72,7 +73,14 @@ public void start()
7273
@Kroll.method
7374
publicTiFileProxystop()
7475
{
75-
returnnewTiFileProxy(TiFileFactory.createTitaniumFile(tiAudioRecorder.stopRecording(), false));
76+
StringfilePath = tiAudioRecorder.stopRecording();
77+
if (filePath != null) {
78+
TiBaseFiletiBaseFile = TiFileFactory.createTitaniumFile(filePath, false);
79+
if (tiBaseFile != null) {
80+
returnnewTiFileProxy(tiBaseFile);
81+
}
82+
}
83+
returnnull;
7684
}
7785

7886
@Kroll.method
@@ -86,4 +94,10 @@ public void pause()
8694
{
8795
tiAudioRecorder.pauseRecording();
8896
}
97+
98+
@Override
99+
publicStringgetApiName()
100+
{
101+
return"Ti.Media.AudioRecorder";
102+
}
89103
}

android/modules/media/src/java/ti/modules/titanium/media/TiAudioRecorder.java

+21-7
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ public TiAudioRecorder()
4949

5050
publicbooleanisPaused()
5151
{
52-
returnpaused;
52+
returnthis.paused;
5353
}
5454

5555
publicbooleanisRecording()
5656
{
57-
returnrecording;
57+
returnthis.recording;
5858
}
5959

6060
publicbooleanisStopped()
6161
{
62-
returnstopped;
62+
returnthis.stopped;
6363
}
6464

6565
publicvoidstartRecording()
@@ -82,7 +82,9 @@ public void startRecording()
8282
audioRecord.setPositionNotificationPeriod(bufferSize / 4);
8383
audioRecord.startRecording();
8484
audioRecord.read(audioData, 0, bufferSize);
85-
recording = true;
85+
this.recording = true;
86+
this.paused = false;
87+
this.stopped = false;
8688
}
8789
}
8890

@@ -91,39 +93,51 @@ public String stopRecording()
9193
FileresultFile = null;
9294
//Guard for calling stop before starting the recording
9395
if (audioRecord != null) {
96+
// Update state.
97+
this.recording = false;
98+
this.paused = false;
99+
this.stopped = true;
100+
101+
// Stop recording.
94102
intrecordState = audioRecord.getState();
95103
if (recordState == 1) {
96104
audioRecord.stop();
97105
}
98106
audioRecord.setRecordPositionUpdateListener(null);
99107
audioRecord.release();
100108
audioRecord = null;
109+
110+
// Write recording to file.
101111
try {
102112
resultFile = TiFileHelper.getInstance().getTempFile(AUDIO_RECORDER_FILE_EXT_WAV, true);
103113
createWaveFile(resultFile.getAbsolutePath());
104114
} catch (IOExceptione) {
105115
e.printStackTrace();
106116
}
107117
}
108-
returnresultFile != null ? resultFile.getAbsolutePath() : "";
118+
returnresultFile != null ? resultFile.getAbsolutePath() : null;
109119
}
110120

111121
publicvoidpauseRecording()
112122
{
113123
//Guard for calling pause before starting the recording
114124
if (audioRecord != null) {
115-
paused = true;
116125
audioRecord.stop();
126+
this.recording = false;
127+
this.paused = true;
128+
this.stopped = false;
117129
}
118130
}
119131

120132
publicvoidresumeRecording()
121133
{
122134
//Guard for calling resume before starting the recording
123135
if (audioRecord != null) {
124-
paused = false;
125136
audioRecord.startRecording();
126137
audioRecord.read(audioData, 0, bufferSize);
138+
this.recording = true;
139+
this.paused = false;
140+
this.stopped = false;
127141
}
128142
}
129143

0 commit comments

Comments
 (0)
close