public static void loadChaptersFromFileUrl(Playable media) { if (media.localFileAvailable()) { ChapterUtils.readID3ChaptersFromPlayableFileUrl(media); if (media.getChapters() == null) { ChapterUtils.readOggChaptersFromPlayableFileUrl(media); } } else { Log.e(TAG, "Could not load chapters from file url: local file not available"); } }
public static void readOggChaptersFromPlayableFileUrl(Playable media) { if (media != null && media.getLocalMediaUrl() != null) { File source = new File(media.getLocalMediaUrl()); if (source.exists()) { InputStream input = null; try { input = new BufferedInputStream(new FileInputStream(source)); readOggChaptersFromInputStream(media, input); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(input); } } } }
public static void loadChaptersFromStreamUrl(Playable media) { if (AppConfig.DEBUG) Log.d(TAG, "Starting chapterLoader thread"); ChapterUtils.readID3ChaptersFromPlayableStreamUrl(media); if (media.getChapters() == null) { ChapterUtils.readOggChaptersFromPlayableStreamUrl(media); } if (AppConfig.DEBUG) Log.d(TAG, "ChapterLoaderThread has finished"); }
public static void readOggChaptersFromPlayableStreamUrl(Playable media) { if (media != null && media.streamAvailable()) { InputStream input = null; try { URL url = new URL(media.getStreamUrl()); input = url.openStream(); if (input != null) { readOggChaptersFromInputStream(media, input); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(input); } } }
/** Uses the file URL of a media object of a feeditem to read its ID3 chapters. */ public static void readID3ChaptersFromPlayableFileUrl(Playable p) { if (AppConfig.DEBUG) Log.d(TAG, "Reading id3 chapters from item " + p.getEpisodeTitle()); if (p != null && p.localFileAvailable() && p.getLocalMediaUrl() != null) { File source = new File(p.getLocalMediaUrl()); if (source.exists()) { ChapterReader reader = new ChapterReader(); InputStream in = null; try { in = new BufferedInputStream(new FileInputStream(source)); reader.readInputStream(in); 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 ID3 chapters"); } } catch (IOException e) { e.printStackTrace(); } catch (ID3ReaderException e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } else { Log.e(TAG, "Unable to read id3 chapters: Source doesn't exist"); } } }
/** Uses the download URL of a media object of a feeditem to read its ID3 chapters. */ public static void readID3ChaptersFromPlayableStreamUrl(Playable p) { if (AppConfig.DEBUG) Log.d(TAG, "Reading id3 chapters from item " + p.getEpisodeTitle()); if (p != null && p.getStreamUrl() != null) { InputStream in = null; try { URL url = new URL(p.getStreamUrl()); ChapterReader reader = new ChapterReader(); in = url.openStream(); reader.readInputStream(in); 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 ID3 chapters"); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ID3ReaderException e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } else { Log.e(TAG, "Unable to read ID3 chapters: media or download URL was null"); } }
/** Calls getCurrentChapter with current position. */ public static Chapter getCurrentChapter(Playable media) { if (media.getChapters() != null) { List<Chapter> chapters = media.getChapters(); Chapter current = null; if (chapters != null) { current = chapters.get(0); for (Chapter sc : chapters) { if (sc.getStart() > media.getPosition()) { break; } else { current = sc; } } } return current; } else { return null; } }
private static void readOggChaptersFromInputStream(Playable p, InputStream input) { if (AppConfig.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(); } }