An {@link IMediaReader} opens up a media container,reads packets from it, decodes the data, and then dispatches information about the data to any registered {@link IMediaListener} objects. The main method ofinterest is {@link #readPacket()}.
Here's an example of a very simple program that prints out a line when the {@link IMediaReader} decides to open a container.
IMediaDebugListener myListener = new MediaListenerAdapter(){ public void onOpen(IMediaGenerator pipe) { System.out.println("opened: " + ((IMediaReader)pipe).getUrl()); } }; IMediaReader reader = ToolFactory.makeReader("myinputfile.flv"); reader.addListener(myListener); while(reader.readPacket() == null) ;
And here's a slightly more involved example where we read a file and display it on screen in real-time:
IMediaReader reader = ToolFactory.makeReader("myinputfile.flv"); reader.addListener(ToolFactory.makeViewer()); while(reader.readPacket() == null) ;
For examples of this class in action, see the com.xuggle.mediatool.demos package.
@author trebor @author aclarke
|
|