A (175)

(Tuis.) #1

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


Creating a VideoView Widget in the FrameLayout


Let’s get started:



  1. Click the activity_play.xml tab to edit your XML UI definition, shown in
    Figure 1 1- 8 , and add a line of space after the opening tag.
    Use a left-facing chevron to open the pop-up widget helper dialog. Find
    the widget and double-click on it to insert it inside of the container.


Figure 11-8. Add a child widget tag inside of the parent tag; add ID, layout parameters



  1. Add an android:id parameter with a value of @+id/videoPlayer, and a
    required layout_width and layout_height parameter, set to the match_parent
    constant, so that the VideoView is scaled to fit inside of the FrameLayout.


Notice the is also configured to match_parent, so the VideoView will be scaled to
fit the screen as well, because both of these UI elements are set to match_parent and the top-most
parent is the display screen.



  1. The next thing that we need to do to prepare this VideoView UI widget for
    use is to declare it in your PlayVideo Activity subclass, at the top of the code
    base, on top of (before) the onCreate( ) method, as seen in Figure 11-9.

Free download pdf