@Override
 public void setListening(boolean listening) {
   if (mListening == listening) return;
   mListening = listening;
   if (listening) {
     mMediaSessionManager.addOnActiveSessionsChangedListener(this, null);
   } else {
     mMediaSessionManager.removeOnActiveSessionsChangedListener(this);
   }
 }
  public VisualizerTile(Host host) {
    super(host);
    mMediaSessionManager =
        (MediaSessionManager) mContext.getSystemService(Context.MEDIA_SESSION_SERVICE);

    // initialize state
    List<MediaController> activeSessions = mMediaSessionManager.getActiveSessions(null);
    for (MediaController activeSession : activeSessions) {
      PlaybackState playbackState = activeSession.getPlaybackState();
      if (playbackState != null && playbackState.getState() == PlaybackState.STATE_PLAYING) {
        mIsAnythingPlaying = true;
        break;
      }
    }
    if (mIsAnythingPlaying && !mLinked) {
      AsyncTask.execute(mLinkVisualizer);
    } else if (!mIsAnythingPlaying && mLinked) {
      AsyncTask.execute(mUnlinkVisualizer);
    }
  }