コード例 #1
0
 public void onConnected() {
   MediaControllerCompat controller =
       ((FragmentActivity) getActivity()).getSupportMediaController();
   LogHelper.d(TAG, "onConnected, mediaController==null? ", controller == null);
   if (controller != null) {
     onMetadataChanged(controller.getMetadata());
     onPlaybackStateChanged(controller.getPlaybackState());
     controller.registerCallback(mCallback);
   }
 }
コード例 #2
0
 @Override
 public void onClick(View v) {
   MediaControllerCompat controller =
       ((FragmentActivity) getActivity()).getSupportMediaController();
   PlaybackStateCompat stateObj = controller.getPlaybackState();
   final int state = stateObj == null ? PlaybackStateCompat.STATE_NONE : stateObj.getState();
   LogHelper.d(TAG, "Button pressed, in state " + state);
   switch (v.getId()) {
     case R.id.play_pause:
       LogHelper.d(TAG, "Play button pressed, in state " + state);
       if (state == PlaybackStateCompat.STATE_PAUSED
           || state == PlaybackStateCompat.STATE_STOPPED
           || state == PlaybackStateCompat.STATE_NONE) {
         playMedia();
       } else if (state == PlaybackStateCompat.STATE_PLAYING
           || state == PlaybackStateCompat.STATE_BUFFERING
           || state == PlaybackStateCompat.STATE_CONNECTING) {
         pauseMedia();
       }
       break;
   }
 }