Skip to content

Commit

Permalink
make sure audio file is done recording before sending
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Dec 13, 2017
1 parent e9c4f21 commit 294c75b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,24 @@ public void onSignalReceived(short[] signal) {
if (!MicrophoneTaskFactory.isRecording()) {
try {
AudioRecorderTask audioRecorderTask = MicrophoneTaskFactory.makeRecorder(context);
audioRecorderTask.setAudioRecorderListener(new AudioRecorderTask.AudioRecorderListener() {
@Override
public void recordingComplete(String path) {

Message message = new Message();
message.what = EventTrigger.MICROPHONE;
message.getData().putString("path",path);
try {
if (serviceMessenger != null)
serviceMessenger.send(message);
} catch (RemoteException e) {
// Cannot happen
}
}
});
audioRecorderTask.start();

Message message = new Message();
message.what = EventTrigger.MICROPHONE;
message.getData().putString("path",audioRecorderTask.getAudioFilePath());
try {
if (serviceMessenger != null)
serviceMessenger.send(message);
} catch (RemoteException e) {
// Cannot happen
}

} catch (MicrophoneTaskFactory.RecordLimitExceeded rle) {
Log.w("MicrophoneMonitor", "We are already recording!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ public class AudioRecorderTask extends Thread {
public boolean isRecording() {
return recording;
}


private AudioRecorderListener mListener;

public interface AudioRecorderListener
{
public void recordingComplete (String path);
}

/**
* We make recorder protected in order to forse
* Factory usage
Expand Down Expand Up @@ -112,11 +119,18 @@ public void run() {

MicrophoneTaskFactory.restartSampling();

if (mListener != null)
mListener.recordingComplete(audioPath.toString());

}

public String getAudioFilePath ()
{
return audioPath.toString();
}

public void setAudioRecorderListener (AudioRecorderListener listener)
{
mListener = listener;
}
}

0 comments on commit 294c75b

Please sign in to comment.