Load chapters of local feed items

This commit is contained in:
ByteHamster 2020-05-25 22:28:42 +02:00
parent 643e970a27
commit 122bed841b
7 changed files with 23 additions and 25 deletions

View File

@ -128,7 +128,7 @@ public class ChaptersFragment extends Fragment {
disposable = Maybe.create(emitter -> {
Playable media = controller.getMedia();
if (media != null) {
media.loadChapterMarks();
media.loadChapterMarks(getContext());
emitter.onSuccess(media);
} else {
emitter.onComplete();

View File

@ -375,7 +375,7 @@ public class FeedMedia extends FeedFile implements Playable {
}
@Override
public void loadChapterMarks() {
public void loadChapterMarks(Context context) {
if (item == null && itemID != 0) {
item = DBReader.getFeedItem(itemID);
}
@ -386,10 +386,10 @@ public class FeedMedia extends FeedFile implements Playable {
if (item.hasChapters()) {
DBReader.loadChaptersOfFeedItem(item);
} else {
if(localFileAvailable()) {
if (localFileAvailable()) {
ChapterUtils.loadChaptersFromFileUrl(this);
} else {
ChapterUtils.loadChaptersFromStreamUrl(this);
ChapterUtils.loadChaptersFromStreamUrl(this, context);
}
if (item.getChapters() != null) {
DBWriter.setFeedItem(item);

View File

@ -311,7 +311,7 @@ public class PlaybackServiceTaskManager {
if (media.getChapters() == null) {
Completable.create(emitter -> {
media.loadChapterMarks();
media.loadChapterMarks(context);
emitter.onComplete();
})
.subscribeOn(Schedulers.io())

View File

@ -1,10 +1,10 @@
package de.danoeh.antennapod.core.util;
import android.content.Context;
import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.util.Log;
import java.util.zip.CheckedOutputStream;
import org.apache.commons.io.IOUtils;
import java.io.BufferedInputStream;
@ -13,7 +13,6 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Collections;
import java.util.List;
@ -49,10 +48,10 @@ public class ChapterUtils {
return chapters.size() - 1;
}
public static void loadChaptersFromStreamUrl(Playable media) {
ChapterUtils.readID3ChaptersFromPlayableStreamUrl(media);
public static void loadChaptersFromStreamUrl(Playable media, Context context) {
ChapterUtils.readID3ChaptersFromPlayableStreamUrl(media, context);
if (media.getChapters() == null) {
ChapterUtils.readOggChaptersFromPlayableStreamUrl(media);
ChapterUtils.readOggChaptersFromPlayableStreamUrl(media, context);
}
}
@ -71,7 +70,7 @@ public class ChapterUtils {
* Uses the download URL of a media object of a feeditem to read its ID3
* chapters.
*/
private static void readID3ChaptersFromPlayableStreamUrl(Playable p) {
private static void readID3ChaptersFromPlayableStreamUrl(Playable p, Context context) {
if (p == null || p.getStreamUrl() == null) {
Log.e(TAG, "Unable to read ID3 chapters: media or download URL was null");
return;
@ -79,8 +78,8 @@ public class ChapterUtils {
Log.d(TAG, "Reading id3 chapters from item " + p.getEpisodeTitle());
CountingInputStream in = null;
try {
URL url = new URL(p.getStreamUrl());
in = new CountingInputStream(url.openStream());
Uri uri = Uri.parse(p.getStreamUrl());
in = new CountingInputStream(context.getContentResolver().openInputStream(uri));
List<Chapter> chapters = readChaptersFrom(in);
if (!chapters.isEmpty()) {
p.setChapters(chapters);
@ -142,14 +141,14 @@ public class ChapterUtils {
return chapters;
}
private static void readOggChaptersFromPlayableStreamUrl(Playable media) {
private static void readOggChaptersFromPlayableStreamUrl(Playable media, Context context) {
if (media == null || !media.streamAvailable()) {
return;
}
InputStream input = null;
try {
URL url = new URL(media.getStreamUrl());
input = url.openStream();
Uri uri = Uri.parse(media.getStreamUrl());
input = context.getContentResolver().openInputStream(uri);
if (input != null) {
readOggChaptersFromInputStream(media, input);
}

View File

@ -103,7 +103,7 @@ public class ExternalMedia implements Playable {
}
@Override
public void loadChapterMarks() {
public void loadChapterMarks(Context context) {
}

View File

@ -4,11 +4,8 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.os.Parcelable;
import android.preference.PreferenceManager;
import androidx.annotation.Nullable;
import android.util.Log;
import java.util.List;
import androidx.annotation.Nullable;
import de.danoeh.antennapod.core.asynctask.ImageResource;
import de.danoeh.antennapod.core.feed.Chapter;
import de.danoeh.antennapod.core.feed.FeedMedia;
@ -17,6 +14,8 @@ import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.util.ShownotesProvider;
import java.util.List;
/**
* Interface for objects that can be played by the PlaybackService.
*/
@ -44,7 +43,7 @@ public interface Playable extends Parcelable,
* Playable objects should load their chapter marks in this method if no
* local file was available when loadMetadata() was called.
*/
void loadChapterMarks();
void loadChapterMarks(Context context);
/**
* Returns the title of the episode that this playable represents

View File

@ -129,8 +129,8 @@ public class RemoteMedia implements Playable {
}
@Override
public void loadChapterMarks() {
ChapterUtils.loadChaptersFromStreamUrl(this);
public void loadChapterMarks(Context context) {
ChapterUtils.loadChaptersFromStreamUrl(this, context);
}
@Override