use of com.google.android.libraries.cast.companionlibrary.cast.MediaQueue in project AntennaPod by AntennaPod.
the class CastManager method onQueueUpdated.
/*
* This is called by onQueueStatusUpdated() of RemoteMediaPlayer
*/
private void onQueueUpdated(List<MediaQueueItem> queueItems, MediaQueueItem item, int repeatMode, boolean shuffle) {
Log.d(TAG, "onQueueUpdated() reached");
Log.d(TAG, String.format("Queue Items size: %d, Item: %s, Repeat Mode: %d, Shuffle: %s", queueItems == null ? 0 : queueItems.size(), item, repeatMode, shuffle));
if (queueItems != null) {
mediaQueue = new MediaQueue(new CopyOnWriteArrayList<>(queueItems), item, shuffle, repeatMode);
} else {
mediaQueue = new MediaQueue(new CopyOnWriteArrayList<>(), null, false, MediaStatus.REPEAT_MODE_REPEAT_OFF);
}
for (CastConsumer consumer : castConsumers) {
consumer.onMediaQueueUpdated(queueItems, item, repeatMode, shuffle);
}
}
use of com.google.android.libraries.cast.companionlibrary.cast.MediaQueue in project Shuttle by timusus.
the class VideoCastControllerFragment method onReady.
/**
* Loads the media on the cast device.
*
* @param mediaInfo The media to be loaded
* @param shouldStartPlayback If {@code true}, playback starts after load automatically
* @param startPoint The position to start the play back
* @param customData An optional custom data to be sent along the load api; it can be
* {@code null}
*/
private void onReady(MediaInfo mediaInfo, boolean shouldStartPlayback, int startPoint, JSONObject customData) {
mSelectedMedia = mediaInfo;
updateClosedCaptionState();
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.isRemoteMediaPlaying()) {
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();
}
MediaQueue mediaQueue = mCastManager.getMediaQueue();
int size = 0;
int position = 0;
if (mediaQueue != null) {
size = mediaQueue.getCount();
position = mediaQueue.getCurrentItemPosition();
}
mCastController.onQueueItemsUpdated(size, position);
updateMetadata();
restartTrickplayTimer();
}
use of com.google.android.libraries.cast.companionlibrary.cast.MediaQueue in project Shuttle by timusus.
the class VideoCastNotificationService method onCreate.
@Override
public void onCreate() {
super.onCreate();
mDimensionInPixels = Utils.convertDpToPixel(VideoCastNotificationService.this, getResources().getDimension(R.dimen.ccl_notification_image_size));
mCastManager = VideoCastManager.getInstance();
readPersistedData();
if (!mCastManager.isConnected() && !mCastManager.isConnecting()) {
mCastManager.reconnectSessionIfPossible();
}
MediaQueue mediaQueue = mCastManager.getMediaQueue();
if (mediaQueue != null) {
int position = mediaQueue.getCurrentItemPosition();
int size = mediaQueue.getCount();
mHasNext = position < (size - 1);
mHasPrev = position > 0;
}
mConsumer = new VideoCastConsumerImpl() {
@Override
public void onApplicationDisconnected(int errorCode) {
LOGD(TAG, "onApplicationDisconnected() was reached, stopping the notification" + " service");
stopSelf();
}
@Override
public void onDisconnected() {
stopSelf();
}
@Override
public void onRemoteMediaPlayerStatusUpdated() {
int mediaStatus = mCastManager.getPlaybackStatus();
VideoCastNotificationService.this.onRemoteMediaPlayerStatusUpdated(mediaStatus);
}
@Override
public void onUiVisibilityChanged(boolean visible) {
mVisible = !visible;
if (mNotification == null) {
try {
setUpNotification(mCastManager.getRemoteMediaInformation());
} catch (TransientNetworkDisconnectionException | NoConnectionException e) {
LOGE(TAG, "onStartCommand() failed to get media", e);
}
}
if (mVisible && (mNotification != null)) {
startForeground(NOTIFICATION_ID, mNotification);
} else {
stopForeground(true);
}
}
@Override
public void onMediaQueueUpdated(List<MediaQueueItem> queueItems, MediaQueueItem item, int repeatMode, boolean shuffle) {
int size = 0;
int position = 0;
if (queueItems != null) {
size = queueItems.size();
position = queueItems.indexOf(item);
}
mHasNext = position < (size - 1);
mHasPrev = position > 0;
}
};
mCastManager.addVideoCastConsumer(mConsumer);
mNotificationActions = mCastManager.getCastConfiguration().getNotificationActions();
List<Integer> notificationCompactActions = mCastManager.getCastConfiguration().getNotificationCompactActions();
if (notificationCompactActions != null) {
mNotificationCompactActionsArray = new int[notificationCompactActions.size()];
for (int i = 0; i < notificationCompactActions.size(); i++) {
mNotificationCompactActionsArray[i] = notificationCompactActions.get(i);
}
}
mForwardTimeInMillis = TimeUnit.SECONDS.toMillis(mCastManager.getCastConfiguration().getForwardStep());
}
use of com.google.android.libraries.cast.companionlibrary.cast.MediaQueue in project zype-android by zype.
the class VideoCastControllerFragment method onReady.
/**
* Loads the media on the cast device.
*
* @param mediaInfo The media to be loaded
* @param shouldStartPlayback If {@code true}, playback starts after load automatically
* @param startPoint The position to start the play back
* @param customData An optional custom data to be sent along the load api; it can be
* {@code null}
*/
private void onReady(MediaInfo mediaInfo, boolean shouldStartPlayback, int startPoint, JSONObject customData) {
mSelectedMedia = mediaInfo;
updateClosedCaptionState();
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.isRemoteMediaPlaying()) {
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();
}
MediaQueue mediaQueue = mCastManager.getMediaQueue();
int size = 0;
int position = 0;
if (mediaQueue != null) {
size = mediaQueue.getCount();
position = mediaQueue.getCurrentItemPosition();
}
mCastController.onQueueItemsUpdated(size, position);
updateMetadata();
restartTrickplayTimer();
}
use of com.google.android.libraries.cast.companionlibrary.cast.MediaQueue in project zype-android by zype.
the class VideoCastControllerFragment method onReady.
/**
* Loads the media on the cast device.
*
* @param mediaInfo The media to be loaded
* @param shouldStartPlayback If {@code true}, playback starts after load automatically
* @param startPoint The position to start the play back
* @param customData An optional custom data to be sent along the load api; it can be
* {@code null}
*/
private void onReady(MediaInfo mediaInfo, boolean shouldStartPlayback, int startPoint, JSONObject customData) {
mSelectedMedia = mediaInfo;
updateClosedCaptionState();
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.isRemoteMediaPlaying()) {
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();
}
MediaQueue mediaQueue = mCastManager.getMediaQueue();
int size = 0;
int position = 0;
if (mediaQueue != null) {
size = mediaQueue.getCount();
position = mediaQueue.getCurrentItemPosition();
}
mCastController.onQueueItemsUpdated(size, position);
updateMetadata();
restartTrickplayTimer();
}
Aggregations