Fixed chapters of non-content uris

This commit is contained in:
ByteHamster 2020-05-26 12:02:56 +02:00
parent 1800704ec2
commit b1ef9f424f
2 changed files with 19 additions and 7 deletions

View File

@ -311,9 +311,9 @@ public class PlaybackServiceTaskManager {
if (media.getChapters() == null) { if (media.getChapters() == null) {
Completable.create(emitter -> { Completable.create(emitter -> {
media.loadChapterMarks(context); media.loadChapterMarks(context);
emitter.onComplete(); emitter.onComplete();
}) })
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(() -> callback.onChapterLoaded(media)); .subscribe(() -> callback.onChapterLoaded(media));

View File

@ -1,5 +1,6 @@
package de.danoeh.antennapod.core.util; package de.danoeh.antennapod.core.util;
import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -13,6 +14,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -78,8 +80,13 @@ public class ChapterUtils {
Log.d(TAG, "Reading id3 chapters from item " + p.getEpisodeTitle()); Log.d(TAG, "Reading id3 chapters from item " + p.getEpisodeTitle());
CountingInputStream in = null; CountingInputStream in = null;
try { try {
Uri uri = Uri.parse(p.getStreamUrl()); if (p.getStreamUrl().startsWith(ContentResolver.SCHEME_CONTENT)) {
in = new CountingInputStream(context.getContentResolver().openInputStream(uri)); Uri uri = Uri.parse(p.getStreamUrl());
in = new CountingInputStream(context.getContentResolver().openInputStream(uri));
} else {
URL url = new URL(p.getStreamUrl());
in = new CountingInputStream(url.openStream());
}
List<Chapter> chapters = readChaptersFrom(in); List<Chapter> chapters = readChaptersFrom(in);
if (!chapters.isEmpty()) { if (!chapters.isEmpty()) {
p.setChapters(chapters); p.setChapters(chapters);
@ -147,8 +154,13 @@ public class ChapterUtils {
} }
InputStream input = null; InputStream input = null;
try { try {
Uri uri = Uri.parse(media.getStreamUrl()); if (media.getStreamUrl().startsWith(ContentResolver.SCHEME_CONTENT)) {
input = context.getContentResolver().openInputStream(uri); Uri uri = Uri.parse(media.getStreamUrl());
input = context.getContentResolver().openInputStream(uri);
} else {
URL url = new URL(media.getStreamUrl());
input = url.openStream();
}
if (input != null) { if (input != null) {
readOggChaptersFromInputStream(media, input); readOggChaptersFromInputStream(media, input);
} }