Skip to content
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

Merged
merged 5 commits into from
Aug 2, 2017

Conversation

ypbnv
Copy link
Contributor

@ypbnv ypbnv commented Aug 1, 2017

JIRA: https://jira.appcelerator.org/browse/TIMOB-1028

Description:
Cherry pick of: #9067

Yordan Banev and others added 4 commits August 1, 2017 11:40
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.
@ypbnv ypbnv added this to the 6.2.0 milestone Aug 1, 2017
@ypbnv ypbnv requested a review from garymathews August 1, 2017 08:45

@Kroll.method
public TiFileProxy stop() {
return new TiFileProxy(TiFileFactory.createTitaniumFile(tiAudioRecorder.stopRecording(),false));
Copy link
Contributor

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");
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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():"";
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after ,

Copy link
Contributor

@garymathews garymathews left a 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.

@lokeshchdhry
Copy link
Contributor

lokeshchdhry commented Aug 1, 2017

FR Passed.

With proper permissions, the audio recorder's record, pause, play, stop works as expected.

  1. Checked by recording audio, stopping & playing it.
  2. Recording audio, pausing , recording again , stopping & playing.

Studio Ver: 4.9.1.201707200100
SDK Ver: 6.2.0.v20170801014621 from jenkins PR
OS Ver: 10.12.3
Xcode Ver: Xcode 8.3.3
Appc NPM: 4.2.9
Appc CLI: 6.2.3-21
Ti CLI Ver: 5.0.14
Alloy Ver: 1.9.13
Node Ver: 6.10.1
Java Ver: 1.8.0_101
Devices: ⇨ google Nexus 5 --- Android 6.0.1

@lokeshchdhry
Copy link
Contributor

Will merge when the requested changes are done.

A more visual appealing container header initialisation.
@ypbnv
Copy link
Contributor Author

ypbnv commented Aug 2, 2017

@garymathews Updated.

Copy link
Contributor

@garymathews garymathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: PASS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants