use of de.danoeh.antennapod.parser.media.id3.ChapterReader in project AntennaPod by AntennaPod.
the class ChapterReaderTest method testReadChapterWithTitle.
@Test
public void testReadChapterWithTitle() throws IOException, ID3ReaderException {
byte[] title = { ID3Reader.ENCODING_ISO, // Title
'H', // Title
'e', // Title
'l', // Title
'l', // Title
'o', // Null-terminated
0 };
byte[] chapterData = Id3ReaderTest.concat(CHAPTER_WITHOUT_SUBFRAME, Id3ReaderTest.generateFrameHeader(ChapterReader.FRAME_ID_TITLE, title.length), title);
FrameHeader header = new FrameHeader(ChapterReader.FRAME_ID_CHAPTER, chapterData.length, (short) 0);
CountingInputStream inputStream = new CountingInputStream(new ByteArrayInputStream(chapterData));
ChapterReader reader = new ChapterReader(inputStream);
Chapter chapter = reader.readChapter(header);
assertEquals(CHAPTER_WITHOUT_SUBFRAME_START_TIME, chapter.getStart());
assertEquals("Hello", chapter.getTitle());
}
use of de.danoeh.antennapod.parser.media.id3.ChapterReader in project AntennaPod by AntennaPod.
the class ChapterUtils method readId3ChaptersFrom.
@NonNull
private static List<Chapter> readId3ChaptersFrom(CountingInputStream in) throws IOException, ID3ReaderException {
ChapterReader reader = new ChapterReader(in);
reader.readInputStream();
List<Chapter> chapters = reader.getChapters();
Collections.sort(chapters, new ChapterStartTimeComparator());
enumerateEmptyChapterTitles(chapters);
if (!chaptersValid(chapters)) {
Log.e(TAG, "Chapter data was invalid");
return Collections.emptyList();
}
return chapters;
}
use of de.danoeh.antennapod.parser.media.id3.ChapterReader in project AntennaPod by AntennaPod.
the class ChapterReaderTest method testReadTitleWithGarbage.
@Test
public void testReadTitleWithGarbage() throws IOException, ID3ReaderException {
byte[] titleSubframeContent = { ID3Reader.ENCODING_ISO, // Title
'A', // Null-terminated
0, // Garbage, should be ignored
42, // Garbage, should be ignored
42, // Garbage, should be ignored
42, // Garbage, should be ignored
42 };
FrameHeader header = new FrameHeader(ChapterReader.FRAME_ID_TITLE, titleSubframeContent.length, (short) 0);
CountingInputStream inputStream = new CountingInputStream(new ByteArrayInputStream(titleSubframeContent));
ChapterReader reader = new ChapterReader(inputStream);
Chapter chapter = new ID3Chapter("", 0);
reader.readChapterSubFrame(header, chapter);
assertEquals("A", chapter.getTitle());
// Should skip the garbage and point to the next frame
assertEquals(titleSubframeContent.length, reader.getPosition());
}
use of de.danoeh.antennapod.parser.media.id3.ChapterReader in project AntennaPod by AntennaPod.
the class ChapterReaderTest method testReadChapterWithoutSubframes.
@Test
public void testReadChapterWithoutSubframes() throws IOException, ID3ReaderException {
FrameHeader header = new FrameHeader(ChapterReader.FRAME_ID_CHAPTER, CHAPTER_WITHOUT_SUBFRAME.length, (short) 0);
CountingInputStream inputStream = new CountingInputStream(new ByteArrayInputStream(CHAPTER_WITHOUT_SUBFRAME));
Chapter chapter = new ChapterReader(inputStream).readChapter(header);
assertEquals(CHAPTER_WITHOUT_SUBFRAME_START_TIME, chapter.getStart());
}
Aggregations