[music] use callback onfailure

This commit is contained in:
aliveoutside
2022-09-20 19:03:06 +03:00
parent 4ac4ae03f1
commit d02d6ceac1
4 changed files with 17 additions and 7 deletions
@@ -39,7 +39,7 @@ public class M3UDownloader implements ITrackDownloader {
client.a(request).a(new okhttp3.Callback() {
@Override
public void a(Call call, IOException e) {
callback.onFailure();
}
@Override
@@ -86,14 +86,18 @@ public class M3UDownloader implements ITrackDownloader {
IOUtils.writeToFile(tsDump, content);
callback.onSizeReceived((long) content.length * tses.size(), parser.getHeapSize());
} catch (IOException | NoSuchPaddingException | NoSuchAlgorithmException | InvalidAlgorithmParameterException | InvalidKeyException e) {
e.printStackTrace();
callback.onFailure();
throw new RuntimeException(e);
}
}));
}
var future = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
future.thenApply(v -> TSMerger.merge(tsesDir, resultTs))
future.exceptionally(throwable -> {
callback.onFailure();
return null;
})
.thenApply(v -> TSMerger.merge(tsesDir, resultTs))
.thenApply(mergeResult -> mergeResult && FFMpeg.convert(resultTs, resultMp3.getAbsolutePath(), track))
.thenApply(convertResult -> {
if (convertResult)
@@ -80,7 +80,8 @@ public class MusicCallbackBuilder {
@Override
public void onFailure() {
notification.setContentText(getString("load_audio_error")).setProgress(0, 0, false);
notificationManager.notify(notificationId, notification.build());
}
@Override
@@ -15,6 +15,7 @@ import java.io.InputStream;
import java.util.stream.Collectors;
import ru.vtosters.lite.utils.AndroidUtils;
import ru.vtosters.lite.utils.IOUtils;
public class FFMpeg {
private static final int BUFFER_SIZE = 2048;
@@ -36,7 +37,7 @@ public class FFMpeg {
sb.append(" -hide_banner");
sb.append(" -write_id3v2 1");
if (track.f != null) {
sb.append(" -metadata title=\"").append(track.f).append("\"");
sb.append(" -metadata title=\"").append(IOUtils.getValidFileName(track.f)).append("\"");
}
if (track.L != null) {
@@ -39,7 +39,9 @@ public class PlaylistDownloader {
}
@Override
public void onFailure() {}
public void onFailure() {
callback.onFailure();
}
@Override
public void onSizeReceived(long size, long header) {}
@@ -63,7 +65,9 @@ public class PlaylistDownloader {
}
@Override
public void onFailure() {}
public void onFailure() {
callback.onFailure();
}
@Override
public void onSizeReceived(long size, long header) {}