com.google.android.gms.cast.MediaStatus Java Examples

The following examples show how to use com.google.android.gms.cast.MediaStatus. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CastPlayback.java    From klingar with Apache License 2.0 6 votes vote down vote up
private static String getPlayerState(int state) {
  switch (state) {
    case MediaStatus.PLAYER_STATE_UNKNOWN:
      return "PLAYER_STATE_UNKNOWN";
    case MediaStatus.PLAYER_STATE_IDLE:
      return "PLAYER_STATE_IDLE";
    case MediaStatus.PLAYER_STATE_BUFFERING:
      return "PLAYER_STATE_BUFFERING";
    case MediaStatus.PLAYER_STATE_PAUSED:
      return "PLAYER_STATE_PAUSED";
    case MediaStatus.PLAYER_STATE_PLAYING:
      return "PLAYER_STATE_PLAYING";
    default:
      return "UNKNOWN";
  }
}
 
Example #2
Source File: GoogleCastRemoteMediaClientListener.java    From react-native-google-cast with MIT License 6 votes vote down vote up
@Override
public void onProgressUpdated(final long progressMs, final long durationMs) {
  module.runOnUiQueueThread(new Runnable() {
    @Override
    public void run() {
      MediaStatus mediaStatus = module.getMediaStatus();
      if (mediaStatus == null) {
        return;
      }

      if (mediaStatus.getPlayerState() == MediaStatus.PLAYER_STATE_PLAYING) {
        module.emitMessageToRN(
            GoogleCastModule.MEDIA_PROGRESS_UPDATED,
            prepareProgressMessage(progressMs, durationMs));
      }
    }
  });
}
 
Example #3
Source File: QueueListAdapter.java    From CastVideos-android with Apache License 2.0 6 votes vote down vote up
private void updatePlayPauseButtonImageResource(ImageButton button) {
    CastSession castSession = CastContext.getSharedInstance(mAppContext)
            .getSessionManager().getCurrentCastSession();
    RemoteMediaClient remoteMediaClient =
            (castSession == null) ? null : castSession.getRemoteMediaClient();
    if (remoteMediaClient == null) {
        button.setVisibility(View.GONE);
        return;
    }
    int status = remoteMediaClient.getPlayerState();
    switch (status) {
        case MediaStatus.PLAYER_STATE_PLAYING:
            button.setImageResource(PAUSE_RESOURCE);
            break;
        case MediaStatus.PLAYER_STATE_PAUSED:
            button.setImageResource(PLAY_RESOURCE);
            break;
        default:
            button.setVisibility(View.GONE);
    }
}
 
Example #4
Source File: QueueDataProvider.java    From CastVideos-android with Apache License 2.0 6 votes vote down vote up
private void updateMediaQueue() {
    RemoteMediaClient remoteMediaClient = getRemoteMediaClient();
    MediaStatus mediaStatus;
    List<MediaQueueItem> queueItems = null;
    if (remoteMediaClient != null) {
        mediaStatus = remoteMediaClient.getMediaStatus();
        if (mediaStatus != null) {
            queueItems = mediaStatus.getQueueItems();
            mRepeatMode = mediaStatus.getQueueRepeatMode();
            mCurrentIem = mediaStatus.getQueueItemById(mediaStatus.getCurrentItemId());
        }
    }
    mQueue.clear();
    if (queueItems == null) {
        Log.d(TAG, "Queue is cleared");
    } else {
        Log.d(TAG, "Queue is updated with a list of size: " + queueItems.size());
        if (queueItems.size() > 0) {
            mQueue.addAll(queueItems);
            mDetachedQueue = false;
        } else {
            mDetachedQueue = true;
        }
    }
}
 
Example #5
Source File: QueueDataProvider.java    From CastVideos-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onPreloadStatusUpdated() {
    RemoteMediaClient remoteMediaClient = getRemoteMediaClient();
    if (remoteMediaClient == null) {
        return;
    }
    MediaStatus mediaStatus = remoteMediaClient.getMediaStatus();
    if (mediaStatus == null) {
        return;
    }
    mUpcomingItem = mediaStatus.getQueueItemById(mediaStatus.getPreloadedItemId());
    Log.d(TAG, "onRemoteMediaPreloadStatusUpdated() with item=" + mUpcomingItem);
    if (mListener != null) {
        mListener.onQueueDataChanged();
    }
}
 
Example #6
Source File: QueueDataProvider.java    From CastVideos-android with Apache License 2.0 6 votes vote down vote up
private void syncWithRemoteQueue() {
    RemoteMediaClient remoteMediaClient = getRemoteMediaClient();
    if (remoteMediaClient != null) {
        remoteMediaClient.registerCallback(mRemoteMediaClientCallback);
        MediaStatus mediaStatus = remoteMediaClient.getMediaStatus();
        if (mediaStatus != null) {
            List<MediaQueueItem> items = mediaStatus.getQueueItems();
            if (items != null && !items.isEmpty()) {
                mQueue.clear();
                mQueue.addAll(items);
                mRepeatMode = mediaStatus.getQueueRepeatMode();
                mCurrentIem = mediaStatus.getQueueItemById(mediaStatus.getCurrentItemId());
                mDetachedQueue = false;
                mUpcomingItem = mediaStatus.getQueueItemById(mediaStatus.getPreloadedItemId());
            }
        }
    }
}
 
Example #7
Source File: VideoCastControllerFragment.java    From UTubeTV with The Unlicense 6 votes vote down vote up
public void onReady(MediaInfo mediaInfo, boolean shouldStartPlayback, int startPoint) {
  mSelectedMedia = mediaInfo;
  try {
    mCastController.setStreamType(mSelectedMedia.getStreamType());
    if (shouldStartPlayback) {
      // need to start remote playback
      mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
      mCastController.setPlaybackStatus(mPlaybackState);
      mCastManager.loadMedia(mSelectedMedia, true, startPoint);
    } else {
      // we don't change the status of remote playback
      if (mCastManager.isRemoteMoviePlaying()) {
        mPlaybackState = MediaStatus.PLAYER_STATE_PLAYING;
      } else {
        mPlaybackState = MediaStatus.PLAYER_STATE_PAUSED;
      }
      mCastController.setPlaybackStatus(mPlaybackState);
    }
  } catch (Exception e) {
    CastUtils.LOGE(TAG, "Failed to get playback and media information", e);
    mCastController.closeActivity();
  }
  updateMetadata();
  restartTrickplayTimer();
}
 
Example #8
Source File: PlaybackControlTest.java    From CastVideos-android with Apache License 2.0 6 votes vote down vote up
/**
 * Play content using the play/pause control and assert player status
 */
@Test
public void testPlayPause() throws InterruptedException, UiObjectNotFoundException {
    mTestUtils.connectToCastDevice();
    mTestUtils.playCastContent(VIDEO_WITHOUT_SUBTITLES);
    mTestUtils.verifyExpandedController();

    onView(withId(R.id.button_play_pause_toggle))
            .perform(click());
    mTestUtils.assertPlayerState(MediaStatus.PLAYER_STATE_PAUSED, MAX_TIMEOUT_MS);

    onView(withId(R.id.button_play_pause_toggle))
            .perform(click());
    mTestUtils.assertPlayerState(MediaStatus.PLAYER_STATE_PLAYING, MAX_TIMEOUT_MS);

    mTestUtils.disconnectFromCastDevice();
}
 
Example #9
Source File: QueueingTest.java    From CastVideos-android with Apache License 2.0 6 votes vote down vote up
/**
 * To add content and create queue
 */
private void createQueue() throws UiObjectNotFoundException, InterruptedException {
    mDevice.findObject(new UiSelector().text(VIDEO_ITEM_1)).click();
    mDevice.findObject(
            new UiSelector().resourceId(resources.getResourceName(R.id.play_circle))).click();
    mDevice.findObject(new UiSelector().text("Add to Queue")).click();
    mTestUtils.assertPlayerState(MediaStatus.PLAYER_STATE_PLAYING, MAX_TIMEOUT_MS);

    mDevice.findObject(new UiSelector().description("Navigate up")).click();

    mDevice.findObject(new UiSelector().text(VIDEO_ITEM_2)).click();
    mDevice.findObject(
            new UiSelector().resourceId(resources.getResourceName(R.id.play_circle))).click();
    mDevice.findObject(new UiSelector().text("Play Next")).click();

    mDevice.findObject(new UiSelector().description("Navigate up")).click();

    mDevice.findObject(new UiSelector().text(VIDEO_ITEM_3)).click();
    mDevice.findObject(
            new UiSelector().resourceId(resources.getResourceName(R.id.play_circle))).click();
    mDevice.findObject(new UiSelector().text("Play Now")).click();
    mTestUtils.assertPlayerState(MediaStatus.PLAYER_STATE_PLAYING, MAX_TIMEOUT_MS);
}
 
Example #10
Source File: VideoCastControllerFragment.java    From UTubeTV with The Unlicense 6 votes vote down vote up
@Override
public void onResume() {
  CastUtils.LOGD(TAG, "onResume() was called");
  try {
    mCastManager = VideoCastManager.getInstance(getActivity());
    boolean shouldFinish = !mCastManager.isConnected() || (mCastManager.getPlaybackStatus() == MediaStatus.PLAYER_STATE_IDLE && mCastManager
        .getIdleReason() == MediaStatus.IDLE_REASON_FINISHED && !mIsFresh);
    if (shouldFinish) {
      mCastController.closeActivity();
    }
    mCastManager.addVideoCastConsumer(mCastConsumer);
    updatePlayerStatus();
    mIsFresh = false;
    mCastManager.incrementUiCounter();
  } catch (CastException e) {
    // logged already
  }
  super.onResume();
}
 
Example #11
Source File: VideoCastControllerFragment.java    From UTubeTV with The Unlicense 6 votes vote down vote up
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
  try {
    if (mPlaybackState == MediaStatus.PLAYER_STATE_PLAYING) {
      mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
      mCastController.setPlaybackStatus(mPlaybackState);
      mCastManager.play(seekBar.getProgress());
    } else if (mPlaybackState == MediaStatus.PLAYER_STATE_PAUSED) {
      mCastManager.seek(seekBar.getProgress());
    }
    restartTrickplayTimer();
  } catch (Exception e) {
    CastUtils.LOGE(TAG, "Failed to complete seek", e);
    mCastController.closeActivity();
  }
}
 
Example #12
Source File: TestUtils.java    From CastVideos-android with Apache License 2.0 6 votes vote down vote up
/**
 * Get and assert player state from remote media client
 */
void assertPlayerState(int expectedState, long timeout) throws InterruptedException {
    long startTime = SystemClock.uptimeMillis();
    actualState = MediaStatus.PLAYER_STATE_UNKNOWN;

    getCastInfo();

    while (actualState != expectedState && SystemClock.uptimeMillis() - startTime < timeout) {
        Thread.sleep(500);
        InstrumentationRegistry.getInstrumentation().runOnMainSync(
                new Runnable() {
                    @Override
                    public void run() {
                        actualState = mRemoteMediaClient.getPlayerState();
                    }
                }
        );
    }

    assertEquals(expectedState, actualState);
}
 
Example #13
Source File: GoogleCastRemoteMediaClientListener.java    From react-native-google-cast with MIT License 6 votes vote down vote up
@NonNull
private WritableMap prepareMessage(MediaStatus mediaStatus) {
  // needs to be constructed for every message from scratch because reusing a
  // message fails with "Map already consumed"
  WritableMap map = Arguments.createMap();
  map.putInt("playerState", mediaStatus.getPlayerState());
  map.putInt("idleReason", mediaStatus.getIdleReason());
  map.putBoolean("muted", mediaStatus.isMute());
  map.putInt("streamPosition", (int)(mediaStatus.getStreamPosition() / 1000));

  MediaInfo info = mediaStatus.getMediaInfo();
  if (info != null) {
    map.putInt("streamDuration", (int) (info.getStreamDuration() / 1000));
  }

  WritableMap message = Arguments.createMap();
  message.putMap("mediaStatus", map);
  return message;
}
 
Example #14
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
private void initRemoteMediaPlayer() {
    mRemoteMediaPlayer = new RemoteMediaPlayer();
    mRemoteMediaPlayer.setOnStatusUpdatedListener( new RemoteMediaPlayer.OnStatusUpdatedListener() {
        @Override
        public void onStatusUpdated() {
            MediaStatus mediaStatus = mRemoteMediaPlayer.getMediaStatus();
            mIsPlaying = mediaStatus.getPlayerState() == MediaStatus.PLAYER_STATE_PLAYING;
        }
    });

    mRemoteMediaPlayer.setOnMetadataUpdatedListener( new RemoteMediaPlayer.OnMetadataUpdatedListener() {
        @Override
        public void onMetadataUpdated() {
        }
    });
}
 
Example #15
Source File: CastPlayback.java    From klingar with Apache License 2.0 6 votes vote down vote up
private static String getIdleReason(int idleReason) {
  switch (idleReason) {
    case MediaStatus.IDLE_REASON_NONE:
      return "IDLE_REASON_NONE";
    case MediaStatus.IDLE_REASON_FINISHED:
      return "IDLE_REASON_FINISHED";
    case MediaStatus.IDLE_REASON_CANCELED:
      return "IDLE_REASON_CANCELED";
    case MediaStatus.IDLE_REASON_INTERRUPTED:
      return "IDLE_REASON_INTERRUPTED";
    case MediaStatus.IDLE_REASON_ERROR:
      return "IDLE_REASON_ERROR";
    default:
      return "UNKNOWN";
  }
}
 
Example #16
Source File: VideoCastControllerFragment.java    From UTubeTV with The Unlicense 6 votes vote down vote up
private void togglePlayback() throws CastException, TransientNetworkDisconnectionException, NoConnectionException {
  switch (mPlaybackState) {
    case MediaStatus.PLAYER_STATE_PAUSED:
      mCastManager.play();
      mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
      restartTrickplayTimer();
      break;
    case MediaStatus.PLAYER_STATE_PLAYING:
      mCastManager.pause();
      mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
      break;
    case MediaStatus.PLAYER_STATE_IDLE:
      if ((mSelectedMedia.getStreamType() == MediaInfo.STREAM_TYPE_LIVE) && (mCastManager.getIdleReason() == MediaStatus.IDLE_REASON_CANCELED)) {
        mCastManager.play();
      } else {
        mCastManager.loadMedia(mSelectedMedia, true, 0);
      }
      mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
      restartTrickplayTimer();
      break;
    default:
      break;
  }
  mCastController.setPlaybackStatus(mPlaybackState);
}
 
Example #17
Source File: VideoCastManager.java    From android with Apache License 2.0 6 votes vote down vote up
/**
 * A helper method to determine if, given a player state and an idle reason (if the state is
 * idle) will warrant having a UI for remote presentation of the remote content.
 *
 * @param state
 * @param idleReason
 * @return
 * @throws TransientNetworkDisconnectionException
 * @throws NoConnectionException
 */
public boolean shouldRemoteUiBeVisible(int state, int idleReason)
        throws TransientNetworkDisconnectionException,
        NoConnectionException {
    switch (state) {
        case MediaStatus.PLAYER_STATE_PLAYING:
        case MediaStatus.PLAYER_STATE_PAUSED:
        case MediaStatus.PLAYER_STATE_BUFFERING:
            return true;
        case MediaStatus.PLAYER_STATE_IDLE:
            if (!isRemoteStreamLive()) {
                return false;
            }
            return idleReason == MediaStatus.IDLE_REASON_CANCELED;
        default:
            break;
    }
    return false;
}
 
Example #18
Source File: VideoCastManager.java    From android with Apache License 2.0 6 votes vote down vote up
/**
 * Toggles the playback of the movie.
 *
 * @throws CastException
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void togglePlayback() throws CastException, TransientNetworkDisconnectionException,
        NoConnectionException {
    checkConnectivity();
    boolean isPlaying = isRemoteMoviePlaying();
    if (isPlaying) {
        pause();
    } else {
        if (mState == MediaStatus.PLAYER_STATE_IDLE
                && mIdleReason == MediaStatus.IDLE_REASON_FINISHED) {
            loadMedia(getRemoteMediaInformation(), true, 0);
        } else {
            play();
        }
    }
}
 
Example #19
Source File: VideoCastControllerActivity.java    From android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mCastManager.isConnected()) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            onVolumeChange((double) mVolumeIncrement);
        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            onVolumeChange(-(double) mVolumeIncrement);
        } else {
            // we don't want to consume non-volume key events
            return super.onKeyDown(keyCode, event);
        }
        if (mCastManager.getPlaybackStatus() == MediaStatus.PLAYER_STATE_PLAYING) {
            return super.onKeyDown(keyCode, event);
        } else {
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
Example #20
Source File: VideoCastControllerFragment.java    From android with Apache License 2.0 6 votes vote down vote up
private void onReady(MediaInfo mediaInfo, boolean shouldStartPlayback, int startPoint,
                     JSONObject customData) {
    mSelectedMedia = mediaInfo;
    try {
        mCastController.setStreamType(mSelectedMedia.getStreamType());
        if (shouldStartPlayback) {
            // need to start remote playback
            mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
            mCastController.setPlaybackStatus(mPlaybackState);
            mCastManager.loadMedia(mSelectedMedia, true, startPoint, customData);
        } else {
            // we don't change the status of remote playback
            if (mCastManager.isRemoteMoviePlaying()) {
                mPlaybackState = MediaStatus.PLAYER_STATE_PLAYING;
            } else {
                mPlaybackState = MediaStatus.PLAYER_STATE_PAUSED;
            }
            mCastController.setPlaybackStatus(mPlaybackState);
        }
    } catch (Exception e) {
        LOGE(TAG, "Failed to get playback and media information", e);
        mCastController.closeActivity();
    }
    updateMetadata();
    restartTrickplayTimer();
}
 
Example #21
Source File: VideoCastControllerFragment.java    From android with Apache License 2.0 6 votes vote down vote up
@Override
public void onResume() {
    LOGD(TAG, "onResume() was called");
    try {
        mCastManager = VideoCastManager.getInstance(getActivity());
        boolean shouldFinish = !mCastManager.isConnected()
                || (mCastManager.getPlaybackStatus() == MediaStatus.PLAYER_STATE_IDLE
                && mCastManager.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED
                && !mIsFresh);
        if (shouldFinish) {
            mCastController.closeActivity();
        }
        mCastManager.addVideoCastConsumer(mCastConsumer);
        mCastManager.incrementUiCounter();
        if (!mIsFresh) updatePlayerStatus();
    } catch (CastException e) {
        // logged already
    }
    super.onResume();
}
 
Example #22
Source File: VideoCastControllerFragment.java    From android with Apache License 2.0 6 votes vote down vote up
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
    try {
        if (mPlaybackState == MediaStatus.PLAYER_STATE_PLAYING) {
            mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
            mCastController.setPlaybackStatus(mPlaybackState);
            mCastManager.play(seekBar.getProgress());
        } else if (mPlaybackState == MediaStatus.PLAYER_STATE_PAUSED) {
            mCastManager.seek(seekBar.getProgress());
        }
        restartTrickplayTimer();
    } catch (Exception e) {
        LOGE(TAG, "Failed to complete seek", e);
        mCastController.closeActivity();
    }
}
 
Example #23
Source File: TVShowActivity.java    From android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mCastManager != null && mCastManager.isConnected()) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            changeVolume(CastApplication.VOLUME_INCREMENT);
        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            changeVolume(-CastApplication.VOLUME_INCREMENT);
        } else {
            // we don't want to consume non-volume key events
            return super.onKeyDown(keyCode, event);
        }
        if (mCastManager.getPlaybackStatus() == MediaStatus.PLAYER_STATE_PLAYING) {
            return super.onKeyDown(keyCode, event);
        } else {
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
Example #24
Source File: MainActivity.java    From android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mCastManager != null && mCastManager.isConnected()) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            changeVolume(CastApplication.VOLUME_INCREMENT);
        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            changeVolume(-CastApplication.VOLUME_INCREMENT);
        } else {
            // we don't want to consume non-volume key events
            return super.onKeyDown(keyCode, event);
        }
        if (mCastManager.getPlaybackStatus() == MediaStatus.PLAYER_STATE_PLAYING) {
            return super.onKeyDown(keyCode, event);
        } else {
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
Example #25
Source File: MovieActivity.java    From android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mCastManager != null && mCastManager.isConnected()) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            changeVolume(CastApplication.VOLUME_INCREMENT);
        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            changeVolume(-CastApplication.VOLUME_INCREMENT);
        } else {
            // we don't want to consume non-volume key events
            return super.onKeyDown(keyCode, event);
        }
        if (mCastManager.getPlaybackStatus() == MediaStatus.PLAYER_STATE_PLAYING) {
            return super.onKeyDown(keyCode, event);
        } else {
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
Example #26
Source File: ChromecastBaseControllerFragment.java    From SkyTube with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Change the visibility of the play/pause/buffering buttons depending on the current playback state.
 */
protected void updateButtons() {
	if(currentPlayerState == MediaStatus.PLAYER_STATE_PLAYING) {
		playButton.setVisibility(View.GONE);
		pauseButton.setVisibility(View.VISIBLE);
		bufferingSpinner.setVisibility(View.GONE);
	} else if(currentPlayerState == MediaStatus.PLAYER_STATE_PAUSED) {
		pauseButton.setVisibility(View.GONE);
		playButton.setVisibility(View.VISIBLE);
		bufferingSpinner.setVisibility(View.GONE);
	} else if(currentPlayerState == MediaStatus.PLAYER_STATE_BUFFERING) {
		pauseButton.setVisibility(View.GONE);
		playButton.setVisibility(View.GONE);
		bufferingSpinner.setVisibility(View.VISIBLE);
	}
}
 
Example #27
Source File: ChromecastMiniControllerFragment.java    From SkyTube with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void init(RemoteMediaClient client, MediaInfo media, int position) {
	super.init(client, media, position);

	videoTitle.setText(video.getTitle());
	channelName.setText(video.getChannelName());

	// We just either started playback of a video, or resumed the cast session. In the latter case, if there's a video playing, let the activity
	// know so that the panel will appear.
	if(currentPlayerState != MediaStatus.PLAYER_STATE_IDLE) {
		activityListener.onPlayStarted();
	}
	chromecastMiniControllerLeftContainer.setAlpha(1);
	chromecastMiniControllerRightContainer.setAlpha(1);
	setDuration((int)client.getStreamDuration());
}
 
Example #28
Source File: BaseActivity.java    From SkyTube with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onResume() {
       /**
        * When resuming, make sure Google Play Services is installed before trying to resume everything for Chromecast support.
        */
	boolean googlePlayServicesAvailable = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS;
	if(googlePlayServicesAvailable) {
		if (mCastSession == null)
			mCastSession = mSessionManager.getCurrentCastSession();
		mSessionManager.addSessionManagerListener(mSessionManagerListener);
		if (mCastSession != null && mCastSession.getRemoteMediaClient() != null) {
			if (mCastSession.getRemoteMediaClient().getPlayerState() != MediaStatus.PLAYER_STATE_IDLE) {
				chromecastMiniControllerFragment.init(mCastSession.getRemoteMediaClient());
				chromecastControllerFragment.init(mCastSession.getRemoteMediaClient());
				showPanel();
			} else
				hidePanel();
		}
		handleNotificationClick(getIntent());
	}
	super.onResume();
}
 
Example #29
Source File: BaseActivity.java    From SkyTube with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSessionResumed(Session session, boolean wasSuspended) {
	mCastSession = CastContext.getSharedInstance(BaseActivity.this).getSessionManager().getCurrentCastSession();
	Runnable r = () -> {
		if(mCastSession.getRemoteMediaClient().getPlayerState() != MediaStatus.PLAYER_STATE_IDLE) {
			chromecastMiniControllerFragment.init(mCastSession.getRemoteMediaClient());
			chromecastControllerFragment.init(mCastSession.getRemoteMediaClient());
			slidingLayout.addPanelSlideListener(getOnPanelDisplayed((int) mCastSession.getRemoteMediaClient().getApproximateStreamPosition(), (int) mCastSession.getRemoteMediaClient().getStreamDuration()));
		} else if(externalPlayIntent != null) {
			// A default Chromecast has been set to handle external intents, and that Chromecast has now been
			// connected to. Play the video (which is stored in externalPlayIntent).
			handleExternalPlayOnChromecast(externalPlayIntent);
			externalPlayIntent = null;
		}
	};
	// Sometimes when we resume a chromecast session, even if media is actually playing, the player state is still idle here.
	// In that case, wait 500ms and check again (above Runnable). But if it's not idle, do the above right away.
	int delay = mCastSession.getRemoteMediaClient().getPlayerState() != MediaStatus.PLAYER_STATE_IDLE ? 0 : 500;
	new Handler().postDelayed(r, delay);

	invalidateOptionsMenu();
	YouTubePlayer.setConnectedToChromecast(true);
	YouTubePlayer.setConnectingToChromecast(false);
}
 
Example #30
Source File: ChromeCastMediaPlayerProfile.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * 再生状態を文字列に変換する.
 * 
 * @param   playState   再生状態
 * @return  再生状態の文字列を返す
 */
public String getPlayStatus(final int playState) {
    switch (playState) {
    case MediaStatus.PLAYER_STATE_BUFFERING:
        return MESSAGE_BUFFERING;
    case MediaStatus.PLAYER_STATE_IDLE:
        return MESSAGE_STOP;
    case MediaStatus.PLAYER_STATE_PAUSED:
        return MESSAGE_PAUSED;
    case MediaStatus.PLAYER_STATE_PLAYING:
        return MESSAGE_PALYING;
    case MediaStatus.PLAYER_STATE_UNKNOWN:
    default:
        return MESSAGE_UNKNOWN;
    }
}