diff --git a/README.md b/README.md index 7424f09..50e910d 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ repositories { } dependencies { - compile 'com.github.adrielcafe:AndroidAudioRecorder:0.0.6' + compile 'com.github.adrielcafe:AndroidAudioRecorder:0.0.7' } ``` @@ -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 diff --git a/app/build.gradle b/app/build.gradle index 3645566..ee383b6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 { diff --git a/build.gradle b/build.gradle index f9552a6..e830e99 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 51cbc7a..2fac210 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/lib/build.gradle b/lib/build.gradle index 8af2c8e..70c1d73 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -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' } \ No newline at end of file diff --git a/lib/src/main/java/cafe/adriel/androidaudiorecorder/AudioRecorderActivity.java b/lib/src/main/java/cafe/adriel/androidaudiorecorder/AudioRecorderActivity.java index ce3574b..2072e01 100644 --- a/lib/src/main/java/cafe/adriel/androidaudiorecorder/AudioRecorderActivity.java +++ b/lib/src/main/java/cafe/adriel/androidaudiorecorder/AudioRecorderActivity.java @@ -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; @@ -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; @@ -120,7 +120,7 @@ public void onResume() { @Override protected void onPause() { - stopRecording(); + restartRecording(null); try { visualizerView.onPause(); } catch (Exception e){ } @@ -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(); } @@ -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() { @@ -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); @@ -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(); @@ -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(); @@ -308,7 +316,6 @@ private void stopPlaying(){ try { player.stop(); player.reset(); - player.release(); } catch (Exception e){ } } @@ -325,7 +332,6 @@ private boolean isPlaying(){ private void startTimer(){ stopTimer(); - secondsElapsed = 0; timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override @@ -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)); } - }); - } + } + }); } } diff --git a/lib/src/main/res/values-pt/strings.xml b/lib/src/main/res/values-pt/strings.xml index efe5524..fa23957 100644 --- a/lib/src/main/res/values-pt/strings.xml +++ b/lib/src/main/res/values-pt/strings.xml @@ -1,5 +1,6 @@ - Savar - Gravando - Reproduzindo + Savar + Pausado + Gravando + Reproduzindo \ No newline at end of file diff --git a/lib/src/main/res/values/strings.xml b/lib/src/main/res/values/strings.xml index 53c5269..bd75cb9 100644 --- a/lib/src/main/res/values/strings.xml +++ b/lib/src/main/res/values/strings.xml @@ -1,6 +1,7 @@ AndroidAudioRecorder Save + Paused Recording Playing \ No newline at end of file diff --git a/screenshots.png b/screenshots.png index b1b2ed2..8eda829 100644 Binary files a/screenshots.png and b/screenshots.png differ