Skip to content

Commit

Permalink
Update AndroidAudioRecorder.java
Browse files Browse the repository at this point in the history
  • Loading branch information
IcyIcarus authored Apr 15, 2017
1 parent 50b62db commit c23ae60
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Intent;
import android.graphics.Color;
import android.os.Environment;
import android.support.v4.app.Fragment;

import cafe.adriel.androidaudiorecorder.model.AudioChannel;
import cafe.adriel.androidaudiorecorder.model.AudioSampleRate;
Expand All @@ -20,6 +21,7 @@ public class AndroidAudioRecorder {
protected static final String EXTRA_KEEP_DISPLAY_ON = "keepDisplayOn";

private Activity activity;
private Fragment fragment;

private String filePath = Environment.getExternalStorageDirectory() + "/recorded_audio.wav";
private AudioSource source = AudioSource.MIC;
Expand All @@ -34,10 +36,18 @@ private AndroidAudioRecorder(Activity activity) {
this.activity = activity;
}

private AndroidAudioRecorder(Fragment fragment) {
this.fragment = fragment;
}

public static AndroidAudioRecorder with(Activity activity) {
return new AndroidAudioRecorder(activity);
}

public static AndroidAudioRecorder with(Fragment fragment) {
return new AndroidAudioRecorder(fragment);
}

public AndroidAudioRecorder setFilePath(String filePath) {
this.filePath = filePath;
return this;
Expand Down Expand Up @@ -90,4 +100,16 @@ public void record() {
activity.startActivityForResult(intent, requestCode);
}

}
public void recordInFragment() {
Intent intent = new Intent(fragment.getActivity(), AudioRecorderActivity.class);
intent.putExtra(EXTRA_FILE_PATH, filePath);
intent.putExtra(EXTRA_COLOR, color);
intent.putExtra(EXTRA_SOURCE, source);
intent.putExtra(EXTRA_CHANNEL, channel);
intent.putExtra(EXTRA_SAMPLE_RATE, sampleRate);
intent.putExtra(EXTRA_AUTO_START, autoStart);
intent.putExtra(EXTRA_KEEP_DISPLAY_ON, keepDisplayOn);
fragment.startActivityForResult(intent, requestCode);
}

}

0 comments on commit c23ae60

Please sign in to comment.