Fields Summary |
---|
final android.content.Context | mContext |
final android.media.AudioManager | mAudioManager |
final android.view.View | mTargetView |
final TransportMediatorCallback | mTransportCallback |
final String | mReceiverAction |
final android.content.IntentFilter | mReceiverFilter |
final android.content.Intent | mIntent |
final ViewTreeObserver.OnWindowAttachListener | mWindowAttachListener |
final ViewTreeObserver.OnWindowFocusChangeListener | mWindowFocusListener |
final android.content.BroadcastReceiver | mMediaButtonReceiver |
AudioManager.OnAudioFocusChangeListener | mAudioFocusChangeListener |
android.app.PendingIntent | mPendingIntent |
android.media.RemoteControlClient | mRemoteControl |
boolean | mFocused |
int | mPlayState |
boolean | mAudioFocused |
Methods Summary |
---|
public void | destroy()
windowDetached();
mTargetView.getViewTreeObserver().removeOnWindowAttachListener(mWindowAttachListener);
mTargetView.getViewTreeObserver().removeOnWindowFocusChangeListener(mWindowFocusListener);
|
void | dropAudioFocus()
if (mAudioFocused) {
mAudioFocused = false;
mAudioManager.abandonAudioFocus(mAudioFocusChangeListener);
}
|
void | gainFocus()
if (!mFocused) {
mFocused = true;
mAudioManager.registerMediaButtonEventReceiver(mPendingIntent);
mAudioManager.registerRemoteControlClient(mRemoteControl);
if (mPlayState == RemoteControlClient.PLAYSTATE_PLAYING) {
takeAudioFocus();
}
}
|
public java.lang.Object | getRemoteControlClient()
return mRemoteControl;
|
void | loseFocus()
dropAudioFocus();
if (mFocused) {
mFocused = false;
mAudioManager.unregisterRemoteControlClient(mRemoteControl);
mAudioManager.unregisterMediaButtonEventReceiver(mPendingIntent);
}
|
public long | onGetPlaybackPosition()
return mTransportCallback.getPlaybackPosition();
|
public void | onPlaybackPositionUpdate(long newPositionMs)
mTransportCallback.playbackPositionUpdate(newPositionMs);
|
public void | pausePlaying()
if (mPlayState == RemoteControlClient.PLAYSTATE_PLAYING) {
mPlayState = RemoteControlClient.PLAYSTATE_PAUSED;
mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
}
dropAudioFocus();
|
public void | refreshState(boolean playing, long position, int transportControls)
if (mRemoteControl != null) {
mRemoteControl.setPlaybackState(playing ? RemoteControlClient.PLAYSTATE_PLAYING
: RemoteControlClient.PLAYSTATE_STOPPED, position, playing ? 1 : 0);
mRemoteControl.setTransportControlFlags(transportControls);
}
|
public void | startPlaying()
if (mPlayState != RemoteControlClient.PLAYSTATE_PLAYING) {
mPlayState = RemoteControlClient.PLAYSTATE_PLAYING;
mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
}
if (mFocused) {
takeAudioFocus();
}
|
public void | stopPlaying()
if (mPlayState != RemoteControlClient.PLAYSTATE_STOPPED) {
mPlayState = RemoteControlClient.PLAYSTATE_STOPPED;
mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
}
dropAudioFocus();
|
void | takeAudioFocus()
if (!mAudioFocused) {
mAudioFocused = true;
mAudioManager.requestAudioFocus(mAudioFocusChangeListener,
AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
}
|
void | windowAttached()
mContext.registerReceiver(mMediaButtonReceiver, mReceiverFilter);
mPendingIntent = PendingIntent.getBroadcast(mContext, 0, mIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
mRemoteControl = new RemoteControlClient(mPendingIntent);
mRemoteControl.setOnGetPlaybackPositionListener(this);
mRemoteControl.setPlaybackPositionUpdateListener(this);
|
void | windowDetached()
loseFocus();
if (mPendingIntent != null) {
mContext.unregisterReceiver(mMediaButtonReceiver);
mPendingIntent.cancel();
mPendingIntent = null;
mRemoteControl = null;
}
|