Preface
This chapter is about android. widget. MediaController. The version is Android 2.3 r1 and translated from "Tang Ming". Thank you again "Tang Ming "! I look forward to your participation in Android Chinese API translation, contact me over140@gmail.com.
Statement
You are welcome to repost, but please keep the original source of the article :)
Blog Garden: http://www.cnblogs.com/
Android Chinese translation group: http://goo.gl/6vJQl
Body
I. Structure
Public class MediaController extends FrameLayout
Java. lang. Object
Android. view. View
Android. view. ViewGroup
Android. widget. FrameLayout
Android. widget. MediaController
Ii. Category Overview
A view that contains the MediaPlayer control. Includes some typical buttons, such as "Play/Pause", "Rewind", and "Fast Forward) "And progress slider (progress slider ). It manages the status of the Media Player (MediaController) to keep the control synchronized.
This class is instantiated by programming. This media controller creates controls with default settings and places them in a window floating on your application. Specifically, these controls float on the view specified by setAnchorView. If the window is idle for 3 seconds, it disappears until it is reproduced when you touch the view.
When a media controller is created in an XML layout resource file, functions such as show () and hide () are invalid. The media player will display and hide the following rules:
* Before calling the setPrevNextListeners () function, the "previous" and "next" buttons are hidden.
* If the setPrevNextListeners () function is called but the input listener parameter is null, the "previous" and "next" buttons are visible but disabled.
* The "rewind" and "fastforward" buttons are displayed. You can use the constructor MediaController (Context, boolean) to set boolean to false.
Iii. Public Methods
Public booleanDispatchKeyEvent(KeyEvent event)
Distribute button events to the next view in the focus path. This path traverses from the top of the view tree to the view with the current focus. If the current view has received focus, it is distributed to itself. Otherwise, it is distributed to the focus path of the next node. This method can also stimulate any button message listener.
Parameters
Events to be distributed
Return Value
If this event is processed, true is returned; otherwise, false is returned.
Public voidHide()
Remove the controller from the screen.
Public booleanIsShowing()
(Translator's note: determines whether the media controller is visible .)
Public voidOnFinishInflate()
Called when the XML file loads the view. This function is called at the final stage of loading, and all child views have been added.
Even if the subclass overrides the onFinishInflate method, always make sure to call the parent class method so that we can call it.
Public booleanOnTouchEvent(MotionEvent event)
Implement this method to handle events triggered by the touch screen.
Parameters
Event Action event
Return Value
If this event is processed, true is returned; otherwise, false is returned.
Public booleanOnTrackballEvent(MotionEvent ev)
This method is used to handle the trackball Action events. The last event of the trackball relative motion can be used.MotionEvent.getX()
AndMotionEvent.getY()
Function acquisition. These are all standardized. 1 indicates that the user presses the next DPAD button. Therefore, they often use small numbers to provide more subtle motion information for the trackball. KEYCODE_DPAD_CENTER (center), KeyEvent. KEYCODE_DPAD_DOWN (down), KeyEvent. KEYCODE_DPAD_LEFT (left), KeyEvent. KEYCODE_DPAD_RIGHT (to the right), KeyEvent. KEYCODE_DPAD_UP (up) for comparison. Center, move down, move left, move right, move up, respectively. Link: onTrackBallEvent Method Introduction)
Parameters
Ev Action event
Return Value
If this event is processed, true is returned; otherwise, false is returned.
Public void setAnchorView (View view)
Set this controller to bind (anchor/anchor) to a view. For example, it can be a VideoView object or the main view of your activity.
Parameters
View is visible when a view is bound to a controller
Public voidSetEnabled(Boolean enabled)
Sets the valid status of the view object. This can also change the valid status of the subclass.
Parameters
Enabled: If you want to make this view object available, set it to true; otherwise, set it to false.
Public voidSetMediaPlayer(MediaController. MediaPlayerControl player)
(Note: set this media controller to a VideoView object .)
Public voidSetPrevNextListeners(View. OnClickListener next, View. OnClickListener prev)
(Note: Set listener functions for the "previous" and "next" buttons .)
Public voidShow(Int timeout)
The Controller is displayed on the screen. It will automatically disappear after the idle 'timeout (timeout) 'milliseconds have elapsed.
Parameters
The timeout parameter is in milliseconds. If it is set to 0, it will be displayed until the hide () function is called.
Public voidShow()
The Controller is displayed on the screen. It will automatically disappear in 3 seconds.
Iv. Supplement
Article Selection
[Recommended] [Android Learning Guide] Android multimedia (Media)
Call android api to play videos
Customize android VideoView (ii)
End
Sorry! It was very busy at the end of the year, and there was a delay in the Progress. Come in and keep the progress at the lowest level, and strive to complete the goal of article 100 by the next weekend (Spring Festival). Thank you for your support, welcome to join us to stick to this huge project.