Search in sources :

Example 1 with VorbisCommentReaderException

use of de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentReaderException in project AntennaPod by AntennaPod.

the class ChapterUtils method readOggChaptersFromInputStream.

private static void readOggChaptersFromInputStream(Playable p, InputStream input) {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "Trying to read chapters from item with title " + p.getEpisodeTitle());
    try {
        VorbisCommentChapterReader reader = new VorbisCommentChapterReader();
        reader.readInputStream(input);
        List<Chapter> chapters = reader.getChapters();
        if (chapters != null) {
            Collections.sort(chapters, new ChapterStartTimeComparator());
            processChapters(chapters, p);
            if (chaptersValid(chapters)) {
                p.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();
    }
}
Also used : ChapterStartTimeComparator(de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator) Chapter(de.danoeh.antennapod.core.feed.Chapter) VorbisCommentReaderException(de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentReaderException) VorbisCommentChapterReader(de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentChapterReader)

Example 2 with VorbisCommentReaderException

use of de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentReaderException in project AntennaPod by AntennaPod.

the class VorbisCommentChapter method getStartTimeFromValue.

public static long getStartTimeFromValue(String value) throws VorbisCommentReaderException {
    String[] parts = value.split(":");
    if (parts.length >= 3) {
        try {
            long hours = TimeUnit.MILLISECONDS.convert(Long.parseLong(parts[0]), TimeUnit.HOURS);
            long minutes = TimeUnit.MILLISECONDS.convert(Long.parseLong(parts[1]), TimeUnit.MINUTES);
            if (parts[2].contains("-->")) {
                parts[2] = parts[2].substring(0, parts[2].indexOf("-->"));
            }
            long seconds = TimeUnit.MILLISECONDS.convert(((long) Float.parseFloat(parts[2])), TimeUnit.SECONDS);
            return hours + minutes + seconds;
        } catch (NumberFormatException e) {
            throw new VorbisCommentReaderException(e);
        }
    } else {
        throw new VorbisCommentReaderException("Invalid time string");
    }
}
Also used : VorbisCommentReaderException(de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentReaderException)

Aggregations

VorbisCommentReaderException (de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentReaderException)2 Chapter (de.danoeh.antennapod.core.feed.Chapter)1 ChapterStartTimeComparator (de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator)1 VorbisCommentChapterReader (de.danoeh.antennapod.core.util.vorbiscommentreader.VorbisCommentChapterReader)1