From 317824140b1bc0bdf89953b6e73131808028c84b Mon Sep 17 00:00:00 2001 From: Dimowner Date: Sun, 29 Mar 2020 13:40:42 +0300 Subject: [PATCH] UI and Audio decoder fixes. --- .../audiorecorder/app/DownloadService.java | 10 +++++++--- .../audiorecorder/app/main/MainPresenter.java | 6 ++++++ .../audiorecorder/audio/AudioDecoder.java | 11 ++++++----- app/src/main/res/values-bg/strings.xml | Bin 15270 -> 15268 bytes app/src/main/res/values-ru/strings.xml | 2 +- app/src/main/res/values-uk/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/DownloadService.java b/app/src/main/java/com/dimowner/audiorecorder/app/DownloadService.java index 75a09c44..177e426f 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/DownloadService.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/DownloadService.java @@ -125,9 +125,13 @@ public int onStartCommand(Intent intent, int flags, int startId) { } public void startDownload(String name, String path) { - recordName = name; - copyFile(name, path); - startNotification(); + if (name == null || path == null) { + stopService(); + } else { + recordName = name; + copyFile(name, path); + startNotification(); + } } private void copyFile(final String name, final String path) { diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/main/MainPresenter.java b/app/src/main/java/com/dimowner/audiorecorder/app/main/MainPresenter.java index f3bc6a36..9b70bb7b 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/app/main/MainPresenter.java +++ b/app/src/main/java/com/dimowner/audiorecorder/app/main/MainPresenter.java @@ -596,6 +596,10 @@ public void run() { public void run() { if (view != null) { view.hideProgress(); + view.showWaveForm(new int[]{}, 0); + view.showName(""); + view.showDuration(TimeUtils.formatTimeIntervalHourMinSec2(0)); + view.hideOptionsMenu(); } } }); @@ -689,6 +693,7 @@ public void run() { view.showMessage(R.string.record_moved_into_trash); } view.hideOptionsMenu(); + view.onPlayProgress(0, 0, 0); view.hideProgress(); record = null; } @@ -783,6 +788,7 @@ public void run() { view.showDuration(TimeUtils.formatTimeIntervalHourMinSec2(songDuration / 1000)); view.hideProgress(); view.hideImportProgress(); + view.showOptionsMenu(); } } }); diff --git a/app/src/main/java/com/dimowner/audiorecorder/audio/AudioDecoder.java b/app/src/main/java/com/dimowner/audiorecorder/audio/AudioDecoder.java index 91a1b055..b421f000 100644 --- a/app/src/main/java/com/dimowner/audiorecorder/audio/AudioDecoder.java +++ b/app/src/main/java/com/dimowner/audiorecorder/audio/AudioDecoder.java @@ -49,7 +49,7 @@ public class AudioDecoder { private int frameIndex = 0; private long duration; - private static final String[] SUPPORTED_EXT = new String[]{"mp3", "wav", "3gpp", "3gp", "amr", "aac", "m4a", "mp4", "ogg"}; + private static final String[] SUPPORTED_EXT = new String[]{"mp3", "wav", "3gpp", "3gp", "amr", "aac", "m4a", "mp4", "ogg", "flac"}; private IntArrayList gains; @@ -125,6 +125,7 @@ private void decodeFile(@NonNull final File mInputFile, @NonNull final DecodeLis decoder.setCallback(new MediaCodec.Callback() { private boolean mOutputEOS = false; + private boolean mInputEOS = false; @Override public void onError(@NonNull MediaCodec codec, @NonNull MediaCodec.CodecException exception) { @@ -147,7 +148,7 @@ public void onOutputFormatChanged(@NonNull MediaCodec codec, @NonNull MediaForma @Override public void onInputBufferAvailable(@NonNull MediaCodec codec, int index) { - if (mOutputEOS) return; + if (mOutputEOS | mInputEOS) return; try { ByteBuffer inputBuffer; inputBuffer = codec.getInputBuffer(index); @@ -166,11 +167,12 @@ public void onInputBufferAvailable(@NonNull MediaCodec codec, int index) { advanced = extractor.advance(); maxresult = Math.max(maxresult, result); } - } while (result >= 0 && advanced && inputBuffer.capacity() - inputBuffer.limit() > maxresult*3);//3 it is just for insurance. When remove it crash happens. it is ok if replace it by 2 number. + } while (result >= 0 && total < maxresult * 5 && advanced && inputBuffer.capacity() - inputBuffer.limit() > maxresult*3);//3 it is just for insurance. When remove it crash happens. it is ok if replace it by 2 number. if (advanced) { codec.queueInputBuffer(index, 0, total, sampleTime, 0); } else { codec.queueInputBuffer(index, 0, 0, -1, MediaCodec.BUFFER_FLAG_END_OF_STREAM); + mInputEOS = true; } } else { //If QUEUE_INPUT_BUFFER_EFFECTIVE failed then trying this way. @@ -181,12 +183,11 @@ public void onInputBufferAvailable(@NonNull MediaCodec codec, int index) { extractor.advance(); } else { codec.queueInputBuffer(index, 0, 0, -1, MediaCodec.BUFFER_FLAG_END_OF_STREAM); + mInputEOS = true; } } } catch (IllegalStateException | IllegalArgumentException e) { Timber.e(e); - //When crash happens decoding failed. Then just finish decoding by sending END of stream flag. - codec.queueInputBuffer(index, 0, 0, -1, MediaCodec.BUFFER_FLAG_END_OF_STREAM); } } diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 22a249b287de5d26e14e5893b332df0cda38458f..d5cfb5cd716bcf280d0fa6e66087a908c0f123d6 100644 GIT binary patch delta 16 YcmZ2hzNCCZo7m)Ea&DW?iQP~E07r-j2><{9 delta 18 acmZ2dzN~yhn;2v9Открыть с помощью̷ Скачать Скачивание: %s - %s скачано в паку Downloads + %s скачано в паку Download Ошибка при скачивания: %s Скачивание отменено Поделиться diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index d1bfb719..25a446a3 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -48,7 +48,7 @@ Відкрити з допомогою̷ Скачати Скачування: %s - %s скачано папку Downloads + %s скачано папку Download Помилка при скачувані: %s Скачування відмінено Поділитися diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 53634baf..5475469d 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -48,7 +48,7 @@ Open with̷ Download Downloading: %s - %s downloaded to the Downloads directory + %s downloaded to the Download directory Failed to download: %s Downloading canceled Share