FileDocCategorySizeDatePackage
PlayerRecord.javaAPI DocAndroid 5.1 API12475Thu Mar 12 22:22:30 GMT 2015android.media

PlayerRecord

public class PlayerRecord extends Object implements android.os.IBinder.DeathRecipient
hide
Class to handle all the information about a media player, encapsulating information about its use RemoteControlClient, playback type and volume... The lifecycle of each instance is managed by android.media.MediaFocusControl, from its addition to the player stack stack to its release.

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private static int
sLastRccId
A global counter for RemoteControlClient identifiers
public static MediaFocusControl
sController
private final android.app.PendingIntent
mMediaIntent
The target for the ACTION_MEDIA_BUTTON events. Always non null. //FIXME verify
private final android.content.ComponentName
mReceiverComponent
The registered media button event receiver.
private int
mRccId
private android.os.IBinder
mToken
A non-null token implies this record tracks a "live" player whose death is being monitored.
private String
mCallingPackageName
private int
mCallingUid
private IRemoteControlClient
mRcClient
Provides access to the information to display on the remote control. May be null (when a media button event receiver is registered, but no remote control client has been registered)
private RcClientDeathHandler
mRcClientDeathHandler
public int
mPlaybackType
Information only used for non-local playback
public int
mPlaybackVolume
public int
mPlaybackVolumeMax
public int
mPlaybackVolumeHandling
public int
mPlaybackStream
public RccPlaybackState
mPlaybackState
public IRemoteVolumeObserver
mRemoteVolumeObs
Constructors Summary
protected PlayerRecord(android.app.PendingIntent mediaIntent, android.content.ComponentName eventReceiver, android.os.IBinder token)
precondition: mediaIntent != null

        mMediaIntent = mediaIntent;
        mReceiverComponent = eventReceiver;
        mToken = token;
        mCallingUid = -1;
        mRcClient = null;
        mRccId = ++sLastRccId;
        mPlaybackState = new RccPlaybackState(
                RemoteControlClient.PLAYSTATE_STOPPED,
                RemoteControlClient.PLAYBACK_POSITION_INVALID,
                RemoteControlClient.PLAYBACK_SPEED_1X);

        resetPlaybackInfo();
        if (mToken != null) {
            try {
                mToken.linkToDeath(this, 0);
            } catch (RemoteException e) {
                sController.unregisterMediaButtonIntentAsync(mMediaIntent);
            }
        }
    
Methods Summary
public voidbinderDied()

        sController.unregisterMediaButtonIntentAsync(mMediaIntent);
    
public voiddestroy()

        unlinkToRcClientDeath();
        if (mToken != null) {
            mToken.unlinkToDeath(this, 0);
            mToken = null;
        }
    
voiddump(java.io.PrintWriter pw, boolean registrationInfo)

        if (registrationInfo) {
            pw.println("  pi: " + mMediaIntent +
                    " -- pack: " + mCallingPackageName +
                    "  -- ercvr: " + mReceiverComponent +
                    "  -- client: " + mRcClient +
                    "  -- uid: " + mCallingUid +
                    "  -- type: " + mPlaybackType +
                    "  state: " + mPlaybackState);
        } else {
            // emphasis on state
            pw.println("  uid: " + mCallingUid +
                    "  -- id: " + mRccId +
                    "  -- type: " + mPlaybackType +
                    "  -- state: " + mPlaybackState +
                    "  -- vol handling: " + mPlaybackVolumeHandling +
                    "  -- vol: " + mPlaybackVolume +
                    "  -- volMax: " + mPlaybackVolumeMax +
                    "  -- volObs: " + mRemoteVolumeObs);
        }
    
protected voidfinalize()

        destroy(); // unlink exception handled inside method
        super.finalize();
    
protected android.app.PendingIntentgetMediaButtonIntent()

        return mMediaIntent;
    
protected android.content.ComponentNamegetMediaButtonReceiver()

        return mReceiverComponent;
    
protected IRemoteControlClientgetRcc()

        return mRcClient;
    
protected intgetRccId()

        return mRccId;
    
protected booleanhasMatchingMediaButtonIntent(android.app.PendingIntent pi)

        if (mToken != null) {
            return mMediaIntent.equals(pi);
        } else {
            if (mReceiverComponent != null) {
                return mReceiverComponent.equals(pi.getIntent().getComponent());
            } else {
                return false;
            }
        }
    
protected booleanisPlaybackActive()

        return MediaFocusControl.isPlaystateActive(mPlaybackState.mState);
    
protected voidresetControllerInfoForNoRcc()

        // stop monitoring the RCC death
        unlinkToRcClientDeath();
        // reset the RCC-related fields
        mRcClient = null;
        mCallingPackageName = null;
    
protected voidresetControllerInfoForRcc(IRemoteControlClient rcClient, java.lang.String callingPackageName, int uid)

        // already had a remote control client?
        if (mRcClientDeathHandler != null) {
            // stop monitoring the old client's death
            unlinkToRcClientDeath();
        }
        // save the new remote control client
        mRcClient = rcClient;
        mCallingPackageName = callingPackageName;
        mCallingUid = uid;
        if (rcClient == null) {
            // here mcse.mRcClientDeathHandler is null;
            resetPlaybackInfo();
        } else {
            IBinder b = mRcClient.asBinder();
            RcClientDeathHandler rcdh =
                    new RcClientDeathHandler(b, mMediaIntent);
            try {
                b.linkToDeath(rcdh, 0);
            } catch (RemoteException e) {
                // remote control client is DOA, disqualify it
                Log.w(TAG, "registerRemoteControlClient() has a dead client " + b);
                mRcClient = null;
            }
            mRcClientDeathHandler = rcdh;
        }
    
public voidresetPlaybackInfo()

        mPlaybackType = RemoteControlClient.PLAYBACK_TYPE_LOCAL;
        mPlaybackVolume = RemoteControlClient.DEFAULT_PLAYBACK_VOLUME;
        mPlaybackVolumeMax = RemoteControlClient.DEFAULT_PLAYBACK_VOLUME;
        mPlaybackVolumeHandling = RemoteControlClient.DEFAULT_PLAYBACK_VOLUME_HANDLING;
        mPlaybackStream = AudioManager.STREAM_MUSIC;
        mPlaybackState.reset();
        mRemoteVolumeObs = null;
    
protected static voidsetMediaFocusControl(MediaFocusControl mfc)

        sController = mfc;
    
public voidunlinkToRcClientDeath()

        if ((mRcClientDeathHandler != null) && (mRcClientDeathHandler.mCb != null)) {
            try {
                mRcClientDeathHandler.mCb.unlinkToDeath(mRcClientDeathHandler, 0);
                mRcClientDeathHandler = null;
            } catch (java.util.NoSuchElementException e) {
                // not much we can do here
                Log.e(TAG, "Error in unlinkToRcClientDeath()", e);
            }
        }