TransportPerformerpublic abstract class TransportPerformer extends Object Implemented by the playback side of the media system, to respond to
requests to perform actions and to retrieve its current state. These
requests may either come from key events dispatched directly to your UI, or
events sent over a media button event receiver that this class keeps active
while your window is in focus. |
Fields Summary |
---|
static final int | AUDIOFOCUS_GAIN | static final int | AUDIOFOCUS_GAIN_TRANSIENT | static final int | AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK | static final int | AUDIOFOCUS_LOSS | static final int | AUDIOFOCUS_LOSS_TRANSIENT | static final int | AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK |
Methods Summary |
---|
public void | onAudioFocusChange(int focusChange)Report that audio focus has changed on the app. This only happens if
you have indicated you have started playing with
{@link TransportMediator#startPlaying TransportController.startPlaying},
which takes audio focus for you.
int keyCode = 0;
switch (focusChange) {
case AUDIOFOCUS_LOSS:
// This will cause us to stop playback, which means we drop audio focus
// so we will not get any further audio focus gain.
keyCode = TransportMediator.KEYCODE_MEDIA_PAUSE;
break;
}
if (keyCode != 0) {
final long now = SystemClock.uptimeMillis();
onMediaButtonDown(keyCode, new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyCode, 0));
onMediaButtonUp(keyCode, new KeyEvent(now, now, KeyEvent.ACTION_UP, keyCode, 0));
}
| public int | onGetBufferPercentage()Request to find out how much of the media has been buffered on the local device.
return 100;
| public abstract long | onGetCurrentPosition()Request to return the current playback position, in milliseconds.
| public abstract long | onGetDuration()Request to return the duration of the current media, in milliseconds.
| public int | onGetTransportControlFlags()Retrieves the flags for the media transport control buttons that this transport supports.
Result is a combination of the following flags:
{@link TransportMediator#FLAG_KEY_MEDIA_PREVIOUS},
{@link TransportMediator#FLAG_KEY_MEDIA_REWIND},
{@link TransportMediator#FLAG_KEY_MEDIA_PLAY},
{@link TransportMediator#FLAG_KEY_MEDIA_PLAY_PAUSE},
{@link TransportMediator#FLAG_KEY_MEDIA_PAUSE},
{@link TransportMediator#FLAG_KEY_MEDIA_STOP},
{@link TransportMediator#FLAG_KEY_MEDIA_FAST_FORWARD},
{@link TransportMediator#FLAG_KEY_MEDIA_NEXT}
The default implementation returns:
{@link TransportMediator#FLAG_KEY_MEDIA_PLAY},
{@link TransportMediator#FLAG_KEY_MEDIA_PLAY_PAUSE},
{@link TransportMediator#FLAG_KEY_MEDIA_PAUSE}, and
{@link TransportMediator#FLAG_KEY_MEDIA_STOP}
return TransportMediator.FLAG_KEY_MEDIA_PLAY
| TransportMediator.FLAG_KEY_MEDIA_PLAY_PAUSE
| TransportMediator.FLAG_KEY_MEDIA_PAUSE
| TransportMediator.FLAG_KEY_MEDIA_STOP;
| public abstract boolean | onIsPlaying()Request to find out whether the player is currently playing its media.
| public boolean | onMediaButtonDown(int keyCode, android.view.KeyEvent event)Report that a media button has been pressed. This is like
{@link android.view.KeyEvent.Callback#onKeyDown(int, android.view.KeyEvent)} but
will only deliver media keys. The default implementation handles these keys:
- KEYCODE_MEDIA_PLAY: call {@link #onStart}
- KEYCODE_MEDIA_PAUSE: call {@link #onPause}
- KEYCODE_MEDIA_STOP: call {@link #onStop}
- KEYCODE_MEDIA_PLAY_PAUSE and KEYCODE_HEADSETHOOK: call {@link #onPause}
if {@link #onIsPlaying()} returns true, otherwise call {@link #onStart}
switch (keyCode) {
case TransportMediator.KEYCODE_MEDIA_PLAY:
onStart();
return true;
case TransportMediator.KEYCODE_MEDIA_PAUSE:
onPause();
return true;
case KeyEvent.KEYCODE_MEDIA_STOP:
onStop();
return true;
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
case KeyEvent.KEYCODE_HEADSETHOOK:
if (onIsPlaying()) {
onPause();
} else {
onStart();
}
}
return true;
| public boolean | onMediaButtonUp(int keyCode, android.view.KeyEvent event)Report that a media button has been released. This is like
{@link KeyEvent.Callback#onKeyUp(int, android.view.KeyEvent)} but
will only deliver media keys. The default implementation does nothing.
return true;
| public abstract void | onPause()Request to pause playback of the media, staying at the current playback position
and other state so a later call to {@link #onStart()} will resume at the same place.
| public abstract void | onSeekTo(long pos)Request to move the current playback position.
| public abstract void | onStart()Request to start playback on the media, resuming from whatever current state
(position etc) it is in.
| public abstract void | onStop()Request to completely stop playback of the media, clearing whatever state the
player thinks is appropriate.
|
|