414 CHAPTER 11: Digital Video: Streaming Video, MediaPlayer, and MediaController classes
Before we start calling methods off of this videoPlayer VideoView object, let’s get some background
regarding the other classes (and thus objects) that we are about to use in our Java code next,
including both the Uri and the MediaPlayer classes. We will cover the Android Uri class first, since
we need it to reference our video data!
The Uri Class: Referencing the Video Data
URI is an abbreviation for Uniform Resource Indentifier. It’s Uniform because it’s standardized,
it is a Resource because it references a data path to some data (content) which your applications will
operate on (and utilize). It’s an Identifier because it identifies where to go and load the data, which
is also known as the content’s data path. The Android Uri class only capitalizes the U, the industry
term capitalizes all three (URI) letters in the term.
The URI has four parts. First is a URI schema, such as HTTP://. Next comes an authority, like
apress.com. Next comes the data path, such as /data/video. Finally comes the data object itself,
in its file format, such as asset.mp4.
The Uri objects in Android hold a reference to a data path which will be used to access raw or
specialized data of one type or another. One example of such data would be a SQLite database,
or in this case, a digital video asset. Other examples would include a website URL or similar types of
content which an application might use.
The Android Uri class is a direct subclass of the java.lang.Object master class. Just so that you don’t
get confused when you look at the Android developer’s site documentation, note that the java.net.Uri
class exists alongside the android.net.Uri class. However, I suggest that you use the Android-specific
version of the Uri class, since it is optimized for use within the Android OS.
The Uri class is a public abstract class, and has over three dozen methods which allow developers
to work with Uri objects (and data path references). Since this is an Absolute Beginner’s book, we
will not be getting into this Uri class at a great level of depth, but you’re welcome to research it
yourself, on the Android developer website. The Android Uri class hierarchy is structured as follows:
java.lang.Object
android.net.Uri
The Android Uri class is kept in the android.net package, making it a tool for accessing data across
a network. For this reason, the import statement for using the Uri class inside of your Android
application would reference a package path of android.net.Uri, as you will see in the next section
when we implement your Uri object.
The Android Uri class allows developers to create Uri objects that provide what is termed an
immutable URI reference. In Android, you make your objects immutable by placing them into
system memory for use, and we’ll need to do this for our URI data path reference by using Android’s
Uri class and its Uri.parse( ) method.
Your Uri object reference includes a URI specifier, as well as a data path reference, which is the
component of the URI which follows the ‘://’. The Uri class will take care of the process of building
and parsing a Uri object, which will then reference data in a manner which will conform to the
popular RFC 2396 technical specification.