-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[6_2_X][TIMOB-1028] Android: Implement AudioRecorder (Parity) #9268
Conversation
Base functionality added.
Add canRecord property. Clean up code. Add comments.
Change two methods' names to match the update for iOS from 6.1.0. Change docs to include the added methods.
Fix the messed new method names.
|
||
@Kroll.method | ||
public TiFileProxy stop() { | ||
return new TiFileProxy(TiFileFactory.createTitaniumFile(tiAudioRecorder.stopRecording(),false)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after ,
@Kroll.getProperty | ||
public boolean getCanRecord() | ||
{ | ||
return TiApplication.getInstance().getPackageManager().hasSystemFeature( "android.hardware.microphone"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove whitespace after (
|
||
public TiAudioRecorder() { | ||
//Get the minimum buffer size according to the device recording capabilities | ||
bufferSize = AudioRecord.getMinBufferSize(RECORDER_SAMPLE_RATE,RECORDER_CHANNELS,RECORDER_AUDIO_ENCODING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after ,
|
||
public void startRecording() { | ||
try { | ||
tempFileReference = TiFileHelper.getInstance().getTempFile(AUDIO_RECORDER_TEMP_FILE,true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after ,
} | ||
|
||
//Initialize the audio recorded with big enough buffer to ensure smooth reading from it without overlap | ||
audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,RECORDER_SAMPLE_RATE, RECORDER_CHANNELS,RECORDER_AUDIO_ENCODING, bufferSize*4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after ,
audioRecord.release(); | ||
audioRecord = null; | ||
try { | ||
resultFile = TiFileHelper.getInstance().getTempFile(AUDIO_RECORDER_FILE_EXT_WAV,true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after ,
e.printStackTrace(); | ||
} | ||
} | ||
return resultFile != null ? resultFile.getAbsolutePath():""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space before and after :
if (audioRecord != null) { | ||
paused = false; | ||
audioRecord.startRecording(); | ||
audioRecord.read(audioData,0,bufferSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after ,
totalDataLen = totalAudioLen + 36; | ||
|
||
//Write the WAV header | ||
writeWaveFileHeader(out, totalAudioLen, totalDataLen,RECORDER_SAMPLE_RATE, channels, byteRate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after ,
long longSampleRate, int channels, long byteRate) throws IOException { | ||
byte[] header = new byte[44]; | ||
|
||
header[0] = 'R'; // RIFF/WAVE header |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could initialise the array with data instead?
byte[] header = {
'R', 'I', 'F'
...
};
header[42] = (byte) ((totalAudioLen >> 16) & 0xff); | ||
header[43] = (byte) ((totalAudioLen >> 24) & 0xff); | ||
|
||
out.write(header, 0, 44); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
44 -> header.length
@Override | ||
public void onPeriodicNotification(AudioRecord recorder) { | ||
try { | ||
audioRecord.read(audioData,0,bufferSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after ,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above; these changes should also be pushed to master
.
FR Passed. With proper permissions, the audio recorder's record, pause, play, stop works as expected.
Studio Ver: 4.9.1.201707200100 |
Will merge when the requested changes are done. |
A more visual appealing container header initialisation.
@garymathews Updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CR: PASS
JIRA: https://jira.appcelerator.org/browse/TIMOB-1028
Description:
Cherry pick of: #9067