A (175)

(Tuis.) #1

440 CHAPTER 11: Digital Video: Streaming Video, MediaPlayer, and MediaController classes


As you can see, this dialog contains all eight of the nested class callbacks that you learned about in
the previous section of the chapter. Select the first MediaPlayer.OnPreparedListener Anonymous
Inner Type option and double-click on it, which will insert it into your Java code structure. Not only
does it insert the OnPreparedListener( ) method, but it also will add an unimplemented onPrepared( )
method structure, which you usually have to do via another mouse-over operation (this must be new
in Android 4.4; Eclipse just keeps getting better at writing all of this Java code for you).


All you will have to do now is to add the operation that you want to happen during this preparation
phase of your video asset. This would be to set the looping parameter to be true, so that the video
will loop forever.


It is important to notice that I am calling the .setOnPreparedListener( ) method before I call the
.start( ) method, because I don’t want to start the video before I prepare (configure) it for use!
Remember, the order of Java programming statements is extremely important, and putting method
calls in the wrong order would generate unintended results!


Now all you have to do is to add a .setLooping( ) method call and parameter to the public void
onPrepared( ) method inside of the OnPreparedListener( ) method, called off of the MediaPlayer
object named arg0, which Eclipse has created for us. This is all done using the following Java
program logic, shown in Figure 11-34:


videoPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
@Override
public void onPrepared(MediaPlayer arg0){
arg0.setLooping(true);
}
});


Figure 11-33. Type videoPlayer.setOnPreparedListener(new MediaPlayer. and then select OnPreparedListener

Free download pdf