A (175)

(Tuis.) #1

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


This should scale the video asset up to meet each respective side of the user’s display screen.
Before we test this, we will also add a media control transport bar UI element into the mix using the
MediaController class and its partner in crime, the MediaPlayer class.


Now that you know how to implement digital video using only the VideoView and Uri classes,
it is time to get a bit more complicated and learn about the Android MediaPlayer class and
MediaController class. Even though this is an Absolute Beginners book, I wanted to cover the topic
of digital video thoroughly for all of our readers who might wish to implement advanced new media
assets in their application user experience!


Android MediaPlayer: VideoPlayback Engine


The MediaPlayer class is a direct subclass of the java.lang.Object master class. As you know, this
indicates that the Android MediaPlayer class was designedspecifically for the purpose of providing
MediaPlayer objects. These MediaPlayer objects are a part of the VideoView widget, and you will
learn how to make them “visible” to your Java code in the next section of the chapter.


The Android MediaPlayer class hierarchy would therefore be structured as follows:


java.lang.Object



android.media.MediaPlayer



The MediaPlayer class belongs to the android.media package. The import statement for using the
MediaPlayer class in an app would reference the android.media.MediaPlayer.The MediaPlayer
class is a public class, and features nine nested classes. Eight of the nested classes offer
callbacks for determining information regarding operation of MediaPlayer’s video playback engine.
We’ll be using one of these in the next section of the chapter.


The ninth nested class, a MediaPlayer.TrackInfo nested class, is utilized to return video, audio,
or subtitle track metadata information. The MediaPlayer nested class callback that we’ll be
implementing later on in the chapter is the MediaPlayer.OnPreparedListener, which allows us to
configure a MediaPlayer object before the digital video asset playback starts for the first time. Other
often-used callbacks include the MediaPlayer.OnErrorListener, which responds to (or handles)


Figure 11-32. Change to and add Top, Left, Right, Bottom alignParent parameters

Free download pdf