Integrated vorbis chapterreader into app
This commit is contained in:
parent
e6292aec79
commit
313958b487
@ -627,7 +627,7 @@ public class FeedManager {
|
||||
if (itemIndex != -1 && itemIndex < (queue.size() - 1)) {
|
||||
return queue.get(itemIndex + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -1185,6 +1185,10 @@ public class FeedManager {
|
||||
chapter = new ID3Chapter(start, title, item,
|
||||
link);
|
||||
break;
|
||||
case VorbisCommentChapter.CHAPTERTYPE_VORBISCOMMENT_CHAPTER:
|
||||
chapter = new VorbisCommentChapter(start,
|
||||
title, item, link);
|
||||
break;
|
||||
}
|
||||
chapter.setId(chapterCursor
|
||||
.getLong(PodDBAdapter.KEY_ID_INDEX));
|
||||
|
@ -611,6 +611,11 @@ public class PlaybackService extends Service {
|
||||
ChapterUtils
|
||||
.readID3ChaptersFromFeedMediaDownloadUrl(media
|
||||
.getItem());
|
||||
if (media.getItem().getChapters() == null) {
|
||||
ChapterUtils
|
||||
.readOggChaptersFromMediaDownloadUrl(media
|
||||
.getItem());
|
||||
}
|
||||
if (media.getItem().getChapters() != null
|
||||
&& !interrupted()) {
|
||||
sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD,
|
||||
@ -1274,9 +1279,10 @@ public class PlaybackService extends Service {
|
||||
return INVALID_TIME;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void setCurrentlyPlayingMedia(long id) {
|
||||
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
|
||||
SharedPreferences.Editor editor = PreferenceManager
|
||||
.getDefaultSharedPreferences(getApplicationContext()).edit();
|
||||
editor.putLong(PREF_CURRENTLY_PLAYING_MEDIA, id);
|
||||
editor.commit();
|
||||
}
|
||||
|
@ -632,7 +632,8 @@ public class DownloadService extends Service {
|
||||
return false;
|
||||
}
|
||||
if (item.getPubDate() == null) {
|
||||
Log.e(TAG, "Item has no pubDate. Using current time as pubDate");
|
||||
Log.e(TAG,
|
||||
"Item has no pubDate. Using current time as pubDate");
|
||||
if (item.getTitle() != null) {
|
||||
Log.e(TAG, "Title of invalid item: " + item.getTitle());
|
||||
}
|
||||
@ -720,6 +721,10 @@ public class DownloadService extends Service {
|
||||
if (media.getItem().getChapters() == null) {
|
||||
ChapterUtils.readID3ChaptersFromFeedMediaFileUrl(media
|
||||
.getItem());
|
||||
if (media.getItem().getChapters() == null) {
|
||||
ChapterUtils.readOggChaptersFromMediaFileUrl(media
|
||||
.getItem());
|
||||
}
|
||||
if (media.getItem().getChapters() != null) {
|
||||
chaptersRead = true;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package de.danoeh.antennapod.util;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
@ -10,6 +11,8 @@ import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import android.util.Log;
|
||||
import de.danoeh.antennapod.AppConfig;
|
||||
import de.danoeh.antennapod.feed.Chapter;
|
||||
@ -18,6 +21,8 @@ import de.danoeh.antennapod.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.util.comparator.ChapterStartTimeComparator;
|
||||
import de.danoeh.antennapod.util.id3reader.ChapterReader;
|
||||
import de.danoeh.antennapod.util.id3reader.ID3ReaderException;
|
||||
import de.danoeh.antennapod.util.vorbiscommentreader.VorbisCommentChapterReader;
|
||||
import de.danoeh.antennapod.util.vorbiscommentreader.VorbisCommentReaderException;
|
||||
|
||||
/** Utility class for getting chapter data from media files. */
|
||||
public class ChapterUtils {
|
||||
@ -131,6 +136,72 @@ public class ChapterUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void readOggChaptersFromMediaDownloadUrl(FeedItem item) {
|
||||
final FeedMedia media = item.getMedia();
|
||||
if (media != null && media.getDownload_url() != null) {
|
||||
InputStream input = null;
|
||||
try {
|
||||
URL url = new URL(media.getDownload_url());
|
||||
input = url.openStream();
|
||||
if (input != null) {
|
||||
readOggChaptersFromInputStream(item, input);
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void readOggChaptersFromMediaFileUrl(FeedItem item) {
|
||||
final FeedMedia media = item.getMedia();
|
||||
if (media != null && media.getFile_url() != null) {
|
||||
File source = new File(media.getFile_url());
|
||||
if (source.exists()) {
|
||||
InputStream input = null;
|
||||
try {
|
||||
input = new BufferedInputStream(new FileInputStream(source));
|
||||
readOggChaptersFromInputStream(item, input);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void readOggChaptersFromInputStream(FeedItem item,
|
||||
InputStream input) {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG,
|
||||
"Trying to read chapters from item with title "
|
||||
+ item.getTitle());
|
||||
try {
|
||||
VorbisCommentChapterReader reader = new VorbisCommentChapterReader();
|
||||
reader.readInputStream(input);
|
||||
List<Chapter> chapters = reader.getChapters();
|
||||
if (chapters != null) {
|
||||
Collections.sort(chapters, new ChapterStartTimeComparator());
|
||||
processChapters(chapters, item);
|
||||
if (chaptersValid(chapters)) {
|
||||
item.setChapters(chapters);
|
||||
Log.i(TAG, "Chapters loaded");
|
||||
} else {
|
||||
Log.e(TAG, "Chapter data was invalid");
|
||||
}
|
||||
} else {
|
||||
Log.i(TAG,
|
||||
"ChapterReader could not find any Ogg vorbis chapters");
|
||||
}
|
||||
} catch (VorbisCommentReaderException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/** Makes sure that chapter does a title and an item attribute. */
|
||||
private static void processChapters(List<Chapter> chapters, FeedItem item) {
|
||||
for (int i = 0; i < chapters.size(); i++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user