A (175)

(Tuis.) #1
CHAPTER 11: Digital Video: Streaming Video, MediaPlayer, and MediaController classes 415

To optimize the Android operating system and application performance, the Uri class performs a
minimal amount of data path validation. What this means is that methods are not specifically defined
for handling invalid data input, so you will need to define your own. This means the Uri class is very
forgiving in the face of an invalid input specification, but it also means that if the data is invalid, your
user may not get the result that they desire!


This means that as a developer, you have to be very careful in what you are doing, as Uri objects
could return data garbage, rather than throw an exception, unless you specify otherwise in your Java
code. Thus, error trapping and data path validation are left up to the developer to do inside their
code, which is why URI is an advanced area which we are only covering at an introductory level so
that you can load your digital video data!


Now we can use this Uri class and configure our VideoView UI element so we will be able to access
our digital video asset. Let’s do that next, and then we can get into the MediaPlayer class and its
related classes.


The Uri.parse( ) Method: Loading Your VideoView


Here’s how to use the Uri class:



  1. Let’s declare a Uri object at the top of your PlayVideo.java Activity subclass
    underneath the videoPlayer object and name it planetFlyOverUri, using the
    following Java object declaration, which is shown in Figure 11-11:


Uri planetFlyOverUri;

Figure 11-11. Declare a Uri object named planetFlyOverUri at the top of your PlayVideo.java Activity subclass

Free download pdf