Skip to content

Commit

Permalink
0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
adrielcafe committed Aug 25, 2016
1 parent d08d420 commit 0f2890e
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 49 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ repositories {
}
dependencies {
compile 'com.github.adrielcafe:AndroidAudioRecorder:0.0.6'
compile 'com.github.adrielcafe:AndroidAudioRecorder:0.0.7'
}
```

Expand All @@ -60,7 +60,7 @@ dependencies {
- [X] Tint images to black when background color is too bright (thanks to [@prakh25](https://github.com/prakh25))
- [X] Wave visualization based on this [player concept](https://dribbble.com/shots/2369760-Player-Concept)
- [X] Play recorded audio
- [ ] Pause audio
- [X] Pause recording
- [ ] Skip silence

## Dependencies
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
dependencies {
compile 'com.android.support:appcompat-v7:24.1.1'
compile project(':lib')
// compile 'com.github.adrielcafe:AndroidAudioRecorder:0.0.6'
// compile 'com.github.adrielcafe:AndroidAudioRecorder:0.0.7'
}

repositories {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.1.3'
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Aug 02 09:48:12 BRT 2016
#Thu Aug 25 11:20:16 BRT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
2 changes: 1 addition & 1 deletion lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ android {

dependencies {
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.kailashdabhi:om-recorder:1.0.1'
compile 'com.kailashdabhi:om-recorder:1.1.0'
compile 'com.cleveroad:audiovisualization:0.9.4'
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
import omrecorder.Recorder;

public class AudioRecorderActivity extends AppCompatActivity
implements PullTransport.OnAudioChunkPulledListener,
MediaPlayer.OnCompletionListener, MediaPlayer.OnPreparedListener {
implements PullTransport.OnAudioChunkPulledListener, MediaPlayer.OnCompletionListener {

private MediaPlayer player;
private Recorder recorder;
Expand All @@ -38,7 +37,8 @@ public class AudioRecorderActivity extends AppCompatActivity

private Timer timer;
private MenuItem saveMenuItem;
private int secondsElapsed;
private int recorderSecondsElapsed;
private int playerSecondsElapsed;
private boolean isRecording;

private RelativeLayout contentLayout;
Expand Down Expand Up @@ -120,7 +120,7 @@ public void onResume() {

@Override
protected void onPause() {
stopRecording();
restartRecording(null);
try {
visualizerView.onPause();
} catch (Exception e){ }
Expand Down Expand Up @@ -168,19 +168,13 @@ public void onAudioChunkPulled(AudioChunk audioChunk) {
visualizerHandler.onDataReceived(amplitude);
}

@Override
public void onPrepared(final MediaPlayer mediaPlayer) {
if(mediaPlayer != null){

}
}

@Override
public void onCompletion(MediaPlayer mediaPlayer) {
stopPlaying();
}

private void selectAudio() {
stopRecording();
setResult(RESULT_OK);
finish();
}
Expand All @@ -191,16 +185,16 @@ public void toggleRecording(View v) {
@Override
public void run() {
if (isRecording) {
stopRecording();
pauseRecording();
} else {
startRecording();
resumeRecording();
}
}
});
}

public void togglePlaying(View v){
stopRecording();
pauseRecording();
Util.wait(100, new Runnable() {
@Override
public void run() {
Expand All @@ -217,44 +211,48 @@ public void restartRecording(View v){
stopRecording();
stopPlaying();
saveMenuItem.setVisible(false);
statusView.setVisibility(View.INVISIBLE);
restartView.setVisibility(View.INVISIBLE);
playView.setVisibility(View.INVISIBLE);
recordView.setImageResource(R.drawable.aar_ic_rec);
timerView.setText("00:00:00");
secondsElapsed = 0;
recorderSecondsElapsed = 0;
playerSecondsElapsed = 0;
}

private void startRecording() {
private void resumeRecording() {
isRecording = true;
saveMenuItem.setVisible(false);
timerView.setText("00:00:00");
statusView.setText(R.string.aar_recording);
statusView.setVisibility(View.VISIBLE);
restartView.setVisibility(View.INVISIBLE);
playView.setVisibility(View.INVISIBLE);
recordView.setImageResource(R.drawable.aar_ic_stop);
recordView.setImageResource(R.drawable.aar_ic_pause);
playView.setImageResource(R.drawable.aar_ic_play);

visualizerHandler = new VisualizerHandler();
visualizerView.linkTo(visualizerHandler);

recorder = OmRecorder.wav(
new PullTransport.Default(Util.getMic(), AudioRecorderActivity.this),
new File(filePath));
recorder.startRecording();
if(recorder == null) {
timerView.setText("00:00:00");

recorder = OmRecorder.wav(
new PullTransport.Default(Util.getMic(), AudioRecorderActivity.this),
new File(filePath));
}
recorder.resumeRecording();

startTimer();
}

private void stopRecording() {
private void pauseRecording() {
isRecording = false;
if(!isFinishing()) {
saveMenuItem.setVisible(true);
}
statusView.setText("");
statusView.setVisibility(View.INVISIBLE);
// TODO pause and restart recording before showing this button
// restartView.setVisibility(View.VISIBLE);
statusView.setText(R.string.aar_paused);
statusView.setVisibility(View.VISIBLE);
restartView.setVisibility(View.VISIBLE);
playView.setVisibility(View.VISIBLE);
recordView.setImageResource(R.drawable.aar_ic_rec);
playView.setImageResource(R.drawable.aar_ic_play);
Expand All @@ -265,16 +263,25 @@ private void stopRecording() {
visualizerHandler.stop();
}

if (recorder != null) {
recorder.pauseRecording();
}

stopTimer();
}

private void stopRecording(){
recorderSecondsElapsed = 0;
if (recorder != null) {
recorder.stopRecording();
recorder = null;
}

stopTimer();
}

private void startPlaying(){
try {
stopRecording();
player = new MediaPlayer();
player.setDataSource(filePath);
player.prepare();
Expand All @@ -291,8 +298,9 @@ public void run() {
timerView.setText("00:00:00");
statusView.setText(R.string.aar_playing);
statusView.setVisibility(View.VISIBLE);
playView.setImageResource(R.drawable.aar_ic_pause);
playView.setImageResource(R.drawable.aar_ic_stop);

playerSecondsElapsed = 0;
startTimer();
} catch (Exception e){
e.printStackTrace();
Expand All @@ -308,7 +316,6 @@ private void stopPlaying(){
try {
player.stop();
player.reset();
player.release();
} catch (Exception e){ }
}

Expand All @@ -325,7 +332,6 @@ private boolean isPlaying(){

private void startTimer(){
stopTimer();
secondsElapsed = 0;
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
Expand All @@ -339,18 +345,22 @@ private void stopTimer(){
if (timer != null) {
timer.cancel();
timer.purge();
timer = null;
}
}

private void updateTimer() {
if(isRecording || isPlaying()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
secondsElapsed++;
timerView.setText(Util.formatSeconds(secondsElapsed));
runOnUiThread(new Runnable() {
@Override
public void run() {
if(isRecording) {
recorderSecondsElapsed++;
timerView.setText(Util.formatSeconds(recorderSecondsElapsed));
} else if(isPlaying()){
playerSecondsElapsed++;
timerView.setText(Util.formatSeconds(playerSecondsElapsed));
}
});
}
}
});
}
}
7 changes: 4 additions & 3 deletions lib/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<resources>
<string name="save">Savar</string>
<string name="recording">Gravando</string>
<string name="playing">Reproduzindo</string>
<string name="aar_save">Savar</string>
<string name="aar_paused">Pausado</string>
<string name="aar_recording">Gravando</string>
<string name="aar_playing">Reproduzindo</string>
</resources>
1 change: 1 addition & 0 deletions lib/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<resources>
<string name="app_name" translatable="false">AndroidAudioRecorder</string>
<string name="aar_save">Save</string>
<string name="aar_paused">Paused</string>
<string name="aar_recording">Recording</string>
<string name="aar_playing">Playing</string>
</resources>
Binary file modified screenshots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0f2890e

Please sign in to comment.