CHAPTER 11: Digital Video: Streaming Video, MediaPlayer, and MediaController classes 411
- Once Started, the video is playing, and can be “Stopped” by using the
.stop( ) method call, or “Paused” by using the .pause( ) method call. These
three video states, Started (Play), Stopped (Stop), and Paused (Pause) should
be the most familiar to users of digital video, as they are represented by
the three primary buttons that are found on the video transport bar. In the
Android OS, the video transport bar is provided using the MediaController
class. - The final MediaPlayer object digital video playback state is called the
“Playback Completed” state. When the MediaPlayer object reaches this
state, it signifies that your video asset has stopped playing, and has reached
the EOF (End Of File) marker inside your video asset. You can bypass this
Playback Completed state if you have invoked the .setLooping(true) method
call and flag. This would be called off of the MediaPlayer object. In this
use-case, your digital video will continue to loop seamlessly forever, until you
call the .stop( ) method to stop it.
Note There are also .start( ) and .reset( ) method calls available for a MediaPlayer object, which can
start and reset the MediaPlayer object at any time, based on the needs of your Java program logic. If you call
a .start( ) method, your video asset will enter the started state; conversely, if you call a .stop( ) method, your
video will be stopped. Methods do to your video asset what their names suggest that they do.
- Finally, there’s also a .release( ) method call, which invokes an “Ended”
state for a MediaPlayer object. This will “terminate” your MediaPlayer object,
which means that the Android OS will completely remove it from the Android
device’s system memory.
As you will see in the MediaPlayer sections of this chapter, there are other nested classes which
will also allow you to “listen” for errors (MediaPlayer.OnErrorListener), as well as for other
states of the MediaPlayer, such as when it reaches a Playback Completed state (MediaPlayer.
OnCompletionListener).
First, we need to create your
the next logical step in implementing video inside of the HelloUniverse application. Once that is
completed, we can review the MediaPlayer class and all of its related classes, and then get into
some serious Java coding to implement digital video setup and playback!