Skip to content

Commit

Permalink
fix(android): AudioRecorder recording/stopped property handling
Browse files Browse the repository at this point in the history
Fixes TIMOB-28105
  • Loading branch information
jquick-axway authored and sgtcoolguy committed Oct 15, 2020
1 parent f8ec672 commit 340bc36
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiFileProxy;
import org.appcelerator.titanium.io.TiBaseFile;
import org.appcelerator.titanium.io.TiFileFactory;

@Kroll.proxy(creatableInModule = MediaModule.class)
Expand Down Expand Up @@ -72,7 +73,14 @@ public void start()
@Kroll.method
public TiFileProxy stop()
{
return new TiFileProxy(TiFileFactory.createTitaniumFile(tiAudioRecorder.stopRecording(), false));
String filePath = tiAudioRecorder.stopRecording();
if (filePath != null) {
TiBaseFile tiBaseFile = TiFileFactory.createTitaniumFile(filePath, false);
if (tiBaseFile != null) {
return new TiFileProxy(tiBaseFile);
}
}
return null;
}

@Kroll.method
Expand All @@ -86,4 +94,10 @@ public void pause()
{
tiAudioRecorder.pauseRecording();
}

@Override
public String getApiName()
{
return "Ti.Media.AudioRecorder";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ public TiAudioRecorder()

public boolean isPaused()
{
return paused;
return this.paused;
}

public boolean isRecording()
{
return recording;
return this.recording;
}

public boolean isStopped()
{
return stopped;
return this.stopped;
}

public void startRecording()
Expand All @@ -82,7 +82,9 @@ public void startRecording()
audioRecord.setPositionNotificationPeriod(bufferSize / 4);
audioRecord.startRecording();
audioRecord.read(audioData, 0, bufferSize);
recording = true;
this.recording = true;
this.paused = false;
this.stopped = false;
}
}

Expand All @@ -91,39 +93,51 @@ public String stopRecording()
File resultFile = null;
//Guard for calling stop before starting the recording
if (audioRecord != null) {
// Update state.
this.recording = false;
this.paused = false;
this.stopped = true;

// Stop recording.
int recordState = audioRecord.getState();
if (recordState == 1) {
audioRecord.stop();
}
audioRecord.setRecordPositionUpdateListener(null);
audioRecord.release();
audioRecord = null;

// Write recording to file.
try {
resultFile = TiFileHelper.getInstance().getTempFile(AUDIO_RECORDER_FILE_EXT_WAV, true);
createWaveFile(resultFile.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
}
return resultFile != null ? resultFile.getAbsolutePath() : "";
return resultFile != null ? resultFile.getAbsolutePath() : null;
}

public void pauseRecording()
{
//Guard for calling pause before starting the recording
if (audioRecord != null) {
paused = true;
audioRecord.stop();
this.recording = false;
this.paused = true;
this.stopped = false;
}
}

public void resumeRecording()
{
//Guard for calling resume before starting the recording
if (audioRecord != null) {
paused = false;
audioRecord.startRecording();
audioRecord.read(audioData, 0, bufferSize);
this.recording = true;
this.paused = false;
this.stopped = false;
}
}

Expand Down

0 comments on commit 340bc36

Please sign in to comment.