CHAPTER 11: Digital Video: Streaming Video, MediaPlayer, and MediaController classes 439
error messages relating to the digital video asset (file) itself or the (lost) network connection, and
the MediaPlayer.OnCompletionListener, which you can use to trigger other Java programming
structures once your video asset playback cycle has completed.
There is also a MediaPlayer.OnSeekCompletedListener, which is called when a seek operation is
completed, and a MediaPlayer.OnBufferingUpdateListener, which is called in order to obtain data
buffering status for a video asset which is being streamed over a network. There are also a couple
of less-often-utilized nested classes, such as the MediaPlayer.OnTimedTextListener, used when
video timed text becomes available for display, and the MediaPlayer.OnInfoListener, used when
information or warnings regarding video media being used become available for display. These
nested class callbacks are not used that often, at least not to my knowledge, but they are available
to you if you need them for specialized digital video implementation scenarios within your Android
applications.
Now, let’s continue with our Java programming, and implement a MediaPlayer.OnPreparedListener
that will set the digital video asset to loop continuously. Fortunately, we learned about event listeners
early on in the book in Chapter 7, so that I could cover more advanced callbacks, such as this one,
during the second half of the book!
Loop Digital Video: Using .OnPrepareListener( )
Now we are going to implement one of the most-used nested classes for the MediaPlayer
video playback engine class, the MediaPlayer.OnPreparedListener( ), which will allow you
to configure your videoPlay VideoView video asset to loop seamlessly. You do this by calling
a .setOnPreparedListener( ) method off of your videoPlayer object, and inside of that Java
programming construct, you use a new keyword to create an OnPreparedListener( ) method. This is
accomplished via the following initial line of Java code:
videoPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
{ onPrepared() method is in here });
As you can see in Figure 11-33, as you type in the videoPlayer.setOnPreparedListener( ) method
call, off of your videoPlayer VideoView object, as you type in the new and the MediaPlayer and
the period part of the statement, Eclipse will suddenly figure out what you are trying to do, and will
popup a MediaPlayer nested class callback helper dialog, which is shown at the bottom-right corner
of the screenshot that is shown in Figure 11-33.