final int[] counts = new int[2];
// create the container
IContainer container = IContainer.make();
// open the container
if (container.open(TEST_FILE_20_SECONDS, IContainer.Type.READ,
null, false, true) < 0)
throw new IllegalArgumentException(
"could not open: " + TEST_FILE_20_SECONDS);
// create a new media reader
MediaReader mr = new MediaReader(container);
mr.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);
mr.addListener(new MediaViewer(mViewerMode, true));
// setup the the listener
IMediaListener mrl = new MediaListenerAdapter()
{
public void onVideoPicture(IVideoPictureEvent event)
{
assertNotNull("picture should be created", event.getPicture());
assertNotNull("buffered image should be created", event.getImage());
++counts[0];
}
public void onAudioSamples(IAudioSamplesEvent event)
{
assertNotNull("audio samples should be created", event.getAudioSamples());
++counts[1];
}
};
mr.addListener(mrl);
// read all the packets in the media file
IError err = null;
while ((err = mr.readPacket()) == null)
;
// should be at end of file
assertEquals("Loop should complete with an EOF",
IError.Type.ERROR_EOF,
err.getType());
// should have read out the correct number of audio and video frames
assertEquals("incorrect number of video frames:",
counts[0],
TEST_FILE_20_SECONDS_VIDEO_FRAME_COUNT);
assertEquals("incorrect number of audio frames:",
counts[1],
TEST_FILE_20_SECONDS_AUDIO_FRAME_COUNT);
// the container should exist
assertTrue("container should be open", container.isOpened());
// there should exist two streams
assertEquals("container should have two streams",
2, container.getNumStreams());
// both streams should be closed
for (int i = 0; i < container.getNumStreams(); ++i)
assertFalse(container.getStream(i).getStreamCoder().isOpen());
}