FileDocCategorySizeDatePackage
PlayerController.javaAPI DocAndroid 5.1 API7626Thu Mar 12 22:22:44 GMT 2015com.android.onemedia

PlayerController

public class PlayerController extends Object

Fields Summary
private static final String
TAG
public static final int
STATE_DISCONNECTED
public static final int
STATE_CONNECTED
protected android.media.session.MediaController
mController
protected IPlayerService
mBinder
protected MediaController.TransportControls
mTransportControls
private final android.content.Intent
mServiceIntent
private android.app.Activity
mContext
private Listener
mListener
private SessionCallback
mControllerCb
private android.media.session.MediaSessionManager
mManager
private android.os.Handler
mHandler
private boolean
mResumed
private android.graphics.Bitmap
mArt
private android.content.ServiceConnection
mServiceConnection
Constructors Summary
public PlayerController(android.app.Activity context, android.content.Intent serviceIntent)


         
        mContext = context;
        if (serviceIntent == null) {
            mServiceIntent = new Intent(mContext, PlayerService.class);
        } else {
            mServiceIntent = serviceIntent;
        }
        mControllerCb = new SessionCallback();
        mManager = (MediaSessionManager) context
                .getSystemService(Context.MEDIA_SESSION_SERVICE);

        mResumed = false;
    
Methods Summary
private voidbindToService()

        mContext.bindService(mServiceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
    
public MediaSession.TokengetSessionToken()

        if (mBinder != null) {
            try {
                return mBinder.getSessionToken();
            } catch (RemoteException e) {
            }
        }
        return null;
    
public voidonPause()

        mResumed = false;
        Log.d(TAG, "onPause, unbinding from service");
        unbindFromService();
    
public voidonResume()

        mResumed = true;
        Log.d(TAG, "onResume. Binding to service with intent " + mServiceIntent.toString());
        bindToService();
    
public voidpause()

        if (mTransportControls != null) {
            mTransportControls.pause();
        }
    
public voidplay()

        if (mTransportControls != null) {
            mTransportControls.play();
        }
    
public voidsetArt(android.graphics.Bitmap art)

        mArt = art;
        if (mBinder != null) {
            try {
                mBinder.setIcon(art);
            } catch (RemoteException e) {
            }
        }
    
public voidsetContent(java.lang.String source)

        RequestUtils.ContentBuilder bob = new RequestUtils.ContentBuilder();
        bob.setSource(source);
        try {
            mBinder.sendRequest(RequestUtils.ACTION_SET_CONTENT, bob.build(), null);
        } catch (RemoteException e) {
            Log.d(TAG, "setContent failed, service may have died.", e);
        }
    
public voidsetListener(com.android.onemedia.PlayerController$Listener listener)

        mListener = listener;
        Log.d(TAG, "Listener set to " + listener + " session is " + mController);
        if (mListener != null) {
            mHandler = new Handler();
            mListener.onConnectionStateChange(
                    mController == null ? STATE_DISCONNECTED : STATE_CONNECTED);
        }
    
public voidsetNextContent(java.lang.String source)

        RequestUtils.ContentBuilder bob = new RequestUtils.ContentBuilder();
        bob.setSource(source);
        try {
            mBinder.sendRequest(RequestUtils.ACTION_SET_NEXT_CONTENT, bob.build(), null);
        } catch (RemoteException e) {
            Log.d(TAG, "setNexctContent failed, service may have died.", e);
        }
    
public voidshowRoutePicker()

        // TODO
    
private voidunbindFromService()

        mContext.unbindService(mServiceConnection);