CHAPTER 11: Digital Video: Streaming Video, MediaPlayer, and MediaController classes 409
This VideoView class is a public class and has two dozen method calls and callbacks that one might
think of as actually being part of the Android MediaPlayer class, which we’ll be covering in a future
section of the chapter.
You can access these MediaPlayer functions (method calls) via the VideoView class, so, ultimately,
you can view these two classes as inexorably bound together. You will see precisely how these two
key Android classes intertwine as we progress through this chapter, especially when we get into the
Java program logic a bit later on.
We will take a closer look here at some of the more useful video playback control method calls, so
that you are familiar with them, in case you need to implement any of these extended digital video
features in your own video playback applications. In the next section, we will also need to review
Android VideoView’s digital video playback lifecycle, so that you can see exactly how all of the
various video playback “states” all fit together.
The basic VideoView method calls include .pause( ), .resume( ), .stop( ), .start( ), .suspend( ), and
.stopPlayback( ). There’s also a .setVideoURI( ), and a .setMediaController( ) method call, as well
as a .setVideoPath( ) method call which accomplishes much of the same end results as the
.setVideoURI( ) call.
There are four .get( ) method calls for “polling” or “getting” information about digital video assets.
They include .getDuration( ), .getCurrentPosition( ), .getBufferPercentage( ), and .getAudioSessionId( ),
as well as the .isPlaying( ) method call to see if the video is playing back currently.
There are also three .can( ) method calls that ascertain what the VideoView can (or cannot) do,
regarding the MediaPlayer class. These include the .canPause( ), .canSeekBackward( ), and
.canSeekForward( ) method calls.
There are also all of your standard event handling method calls, which are inherited from the
Android View superclass. These include the .onTouchEvent( ), onKeyDown( ), and onTrackballEvent( )
method calls, among all of the other event handlers. The event handler which is usually used with
the VideoView, for instance to bring up the MediaControl “transport” UI panel, is the onTouchEvent( )
event listener.
Finally, there are specialized method calls, such as .resolveAdjustedSize( ) or
.onInitializeAccessibilityEvent( ) that are included to allow developers to implement accessibility
standards if needed for their video playback UI.
A VideoView Lifecycle: Eight Video Playback Stages
Before you start working with the Android digital video-related classes, learn about digital video
concepts, and create custom 3D digital video assets, you’ll need to understand the different “stages”
which a digital video asset goes through in Android. Playing digital video may seem simple from the
end user’s perspective. Play, Pause, Rewind, and Stop all provide basic video transport functions.
All these are involved in the overall video playback process or lifecycle. There are other “under the
hood” stages which allow Android to load the video asset into memory, or to set parameters for
playback and similar system-level considerations. These unseen digital video lifecycle stages will
allow developers the flexibility to create an optimal digital video user experience, and give Android
developers a wider variety of playback options.