|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectandroid.support.v4.media.TransportController
android.support.v4.media.TransportMediator
public class TransportMediator
Helper for implementing a media transport control (with play, pause, skip, and
other media actions). Takes care of both key events and advanced features
like android.media.RemoteControlClient. This class is intended to
serve as an intermediary between transport controls (whether they be on-screen
controls, hardware buttons, remote controls) and the actual player. The player
is represented by a single TransportPerformer that must be supplied to
this class. On-screen controls that want to control and show the state of the
player should do this through calls to the TransportController interface.
Here is a simple but fairly complete sample of a video player that is built around this class. Note that the MediaController class used here is not the one included in the standard Android framework, but a custom implementation. Real applications often implement their own transport controls, or you can copy the implementation here out of Support4Demos.
| Field Summary | |
|---|---|
static int |
FLAG_KEY_MEDIA_FAST_FORWARD
Synonym for {@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_FAST_FORWARD RemoveControlClient.FLAG_KEY_MEDIA_FAST_FORWARD |
static int |
FLAG_KEY_MEDIA_NEXT
Synonym for {@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_NEXT RemoveControlClient.FLAG_KEY_MEDIA_NEXT |
static int |
FLAG_KEY_MEDIA_PAUSE
Synonym for {@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_PAUSE RemoveControlClient.FLAG_KEY_MEDIA_PAUSE |
static int |
FLAG_KEY_MEDIA_PLAY
Synonym for {@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_PLAY RemoveControlClient.FLAG_KEY_MEDIA_PLAY |
static int |
FLAG_KEY_MEDIA_PLAY_PAUSE
Synonym for {@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_PLAY_PAUSE RemoveControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE |
static int |
FLAG_KEY_MEDIA_PREVIOUS
Synonym for {@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_PREVIOUS RemoveControlClient.FLAG_KEY_MEDIA_PREVIOUS |
static int |
FLAG_KEY_MEDIA_REWIND
Synonym for {@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_REWIND RemoveControlClient.FLAG_KEY_MEDIA_REWIND |
static int |
FLAG_KEY_MEDIA_STOP
Synonym for {@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_STOP RemoveControlClient.FLAG_KEY_MEDIA_STOP |
static int |
KEYCODE_MEDIA_PAUSE
Synonym for KeyEvent.KEYCODE_MEDIA_PAUSE |
static int |
KEYCODE_MEDIA_PLAY
Synonym for KeyEvent.KEYCODE_MEDIA_PLAY |
static int |
KEYCODE_MEDIA_RECORD
Synonym for KeyEvent.KEYCODE_MEDIA_RECORD |
| Constructor Summary | |
|---|---|
TransportMediator(android.app.Activity activity,
TransportPerformer callbacks)
|
|
TransportMediator(android.view.View view,
TransportPerformer callbacks)
|
|
| Method Summary | |
|---|---|
void |
destroy()
Optionally call when no longer using the TransportController. |
boolean |
dispatchKeyEvent(android.view.KeyEvent event)
Must call from Activity.dispatchKeyEvent to give
the transport an opportunity to intercept media keys. |
int |
getBufferPercentage()
Retrieve amount, in percentage (0-100), that the media stream has been buffered on to the local device. |
long |
getCurrentPosition()
Retrieve the current playback location in the media stream, in milliseconds. |
long |
getDuration()
Retrieve the total duration of the media stream, in milliseconds. |
java.lang.Object |
getRemoteControlClient()
Return the android.media.RemoteControlClient associated with this transport. |
int |
getTransportControlFlags()
Retrieves the flags for the media transport control buttons that this transport supports. |
boolean |
isPlaying()
Return whether the player is currently playing its stream. |
void |
pausePlaying()
Move the controller into the paused state. |
void |
refreshState()
|
void |
registerStateListener(TransportStateListener listener)
Start listening to changes in playback state. |
void |
seekTo(long pos)
Move to a new location in the media stream. |
void |
startPlaying()
Move the controller into the playing state. |
void |
stopPlaying()
Move the controller into the stopped state. |
void |
unregisterStateListener(TransportStateListener listener)
Stop listening to changes in playback state. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int KEYCODE_MEDIA_PLAY
KeyEvent.KEYCODE_MEDIA_PLAY
public static final int KEYCODE_MEDIA_PAUSE
KeyEvent.KEYCODE_MEDIA_PAUSE
public static final int KEYCODE_MEDIA_RECORD
KeyEvent.KEYCODE_MEDIA_RECORD
public static final int FLAG_KEY_MEDIA_PREVIOUS
public static final int FLAG_KEY_MEDIA_REWIND
public static final int FLAG_KEY_MEDIA_PLAY
public static final int FLAG_KEY_MEDIA_PLAY_PAUSE
public static final int FLAG_KEY_MEDIA_PAUSE
public static final int FLAG_KEY_MEDIA_STOP
public static final int FLAG_KEY_MEDIA_FAST_FORWARD
public static final int FLAG_KEY_MEDIA_NEXT
| Constructor Detail |
|---|
public TransportMediator(android.app.Activity activity,
TransportPerformer callbacks)
public TransportMediator(android.view.View view,
TransportPerformer callbacks)
| Method Detail |
|---|
public java.lang.Object getRemoteControlClient()
android.media.RemoteControlClient associated with this transport.
This returns a generic Object since the RemoteControlClient is not availble before
android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH. Further, this class
will not use RemoteControlClient in its implementation until
android.os.Build.VERSION_CODES#JELLY_BEAN_MR2. You should always check for
null here and not do anything with the RemoteControlClient if none is given; this
way you don't need to worry about the current platform API version.
Note that this class takes possession of the
android.media.RemoteControlClient.OnGetPlaybackPositionListener and
android.media.RemoteControlClient.OnPlaybackPositionUpdateListener callbacks;
you will interact with these through
TransportPerformer.onGetCurrentPosition and
TransportPerformer.onSeekTo, respectively.
public boolean dispatchKeyEvent(android.view.KeyEvent event)
Activity.dispatchKeyEvent to give
the transport an opportunity to intercept media keys. Any such keys will show up
in TransportPerformer.
event - public void registerStateListener(TransportStateListener listener)
TransportController
registerStateListener in class TransportControllerpublic void unregisterStateListener(TransportStateListener listener)
TransportController
unregisterStateListener in class TransportControllerpublic void refreshState()
public void startPlaying()
startPlaying in class TransportControllerpublic void pausePlaying()
pausePlaying in class TransportControllerpublic void stopPlaying()
stopPlaying in class TransportControllerpublic long getDuration()
TransportController
getDuration in class TransportControllerpublic long getCurrentPosition()
TransportController
getCurrentPosition in class TransportControllerpublic void seekTo(long pos)
TransportController
seekTo in class TransportControllerpos - Position to move to, in milliseconds.public boolean isPlaying()
TransportController
isPlaying in class TransportControllerpublic int getBufferPercentage()
TransportController
getBufferPercentage in class TransportControllerpublic int getTransportControlFlags()
FLAG_KEY_MEDIA_PREVIOUS,
FLAG_KEY_MEDIA_REWIND,
FLAG_KEY_MEDIA_PLAY,
FLAG_KEY_MEDIA_PLAY_PAUSE,
FLAG_KEY_MEDIA_PAUSE,
FLAG_KEY_MEDIA_STOP,
FLAG_KEY_MEDIA_FAST_FORWARD,
FLAG_KEY_MEDIA_NEXT
getTransportControlFlags in class TransportControllerpublic void destroy()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||