Skip to content

Commit

Permalink
UI and Audio decoder fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimowner committed Mar 29, 2020
1 parent d9bf1d6 commit 3178241
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
});
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -783,6 +788,7 @@ public void run() {
view.showDuration(TimeUtils.formatTimeIntervalHourMinSec2(songDuration / 1000));
view.hideProgress();
view.hideImportProgress();
view.showOptionsMenu();
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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.
Expand All @@ -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);
}
}

Expand Down
Binary file modified app/src/main/res/values-bg/strings.xml
Binary file not shown.
2 changes: 1 addition & 1 deletion app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<string name="open_with">Открыть с помощью&#823;</string>
<string name="download">Скачать</string>
<string name="downloading">Скачивание: %s</string>
<string name="downloading_success">%s скачано в паку Downloads</string>
<string name="downloading_success">%s скачано в паку Download</string>
<string name="downloading_failed">Ошибка при скачивания: %s</string>
<string name="downloading_cancel">Скачивание отменено</string>
<string name="share">Поделиться</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<string name="open_with">Відкрити з допомогою&#823;</string>
<string name="download">Скачати</string>
<string name="downloading">Скачування: %s</string>
<string name="downloading_success">%s скачано папку Downloads</string>
<string name="downloading_success">%s скачано папку Download</string>
<string name="downloading_failed">Помилка при скачувані: %s</string>
<string name="downloading_cancel">Скачування відмінено</string>
<string name="share">Поділитися</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<string name="open_with">Open with&#823;</string>
<string name="download">Download</string>
<string name="downloading">Downloading: %s</string>
<string name="downloading_success">%s downloaded to the Downloads directory</string>
<string name="downloading_success">%s downloaded to the Download directory</string>
<string name="downloading_failed">Failed to download: %s</string>
<string name="downloading_cancel">Downloading canceled</string>
<string name="share">Share</string>
Expand Down

0 comments on commit 3178241

Please sign in to comment.