use of com.google.android.gms.cast.RemoteMediaPlayer in project AntennaPod by AntennaPod.
the class CastManager method setStreamVolume.
/**
* Sets the stream volume.
*
* @param volume Should be a value between 0 and 1, inclusive.
* @throws NoConnectionException
* @throws TransientNetworkDisconnectionException
* @throws CastException If setting system volume fails
*/
public void setStreamVolume(double volume) throws CastException, TransientNetworkDisconnectionException, NoConnectionException {
checkConnectivity();
if (volume > 1.0) {
volume = 1.0;
} else if (volume < 0) {
volume = 0.0;
}
RemoteMediaPlayer mediaPlayer = getRemoteMediaPlayer();
if (mediaPlayer == null) {
throw new NoConnectionException();
}
mediaPlayer.setStreamVolume(mApiClient, volume).setResultCallback((result) -> {
if (!result.getStatus().isSuccess()) {
onFailed(R.string.cast_failed_setting_volume, result.getStatus().getStatusCode());
} else {
CastManager.this.onStreamVolumeChanged();
}
});
}
use of com.google.android.gms.cast.RemoteMediaPlayer in project Shuttle by timusus.
the class VideoCastManager method attachMediaChannel.
private void attachMediaChannel() throws TransientNetworkDisconnectionException, NoConnectionException {
LOGD(TAG, "attachMediaChannel()");
checkConnectivity();
if (mRemoteMediaPlayer == null) {
mRemoteMediaPlayer = new RemoteMediaPlayer();
mRemoteMediaPlayer.setOnStatusUpdatedListener(new RemoteMediaPlayer.OnStatusUpdatedListener() {
@Override
public void onStatusUpdated() {
LOGD(TAG, "RemoteMediaPlayer::onStatusUpdated() is reached");
VideoCastManager.this.onRemoteMediaPlayerStatusUpdated();
}
});
mRemoteMediaPlayer.setOnPreloadStatusUpdatedListener(new RemoteMediaPlayer.OnPreloadStatusUpdatedListener() {
@Override
public void onPreloadStatusUpdated() {
LOGD(TAG, "RemoteMediaPlayer::onPreloadStatusUpdated() is " + "reached");
VideoCastManager.this.onRemoteMediaPreloadStatusUpdated();
}
});
mRemoteMediaPlayer.setOnMetadataUpdatedListener(new RemoteMediaPlayer.OnMetadataUpdatedListener() {
@Override
public void onMetadataUpdated() {
LOGD(TAG, "RemoteMediaPlayer::onMetadataUpdated() is reached");
VideoCastManager.this.onRemoteMediaPlayerMetadataUpdated();
}
});
mRemoteMediaPlayer.setOnQueueStatusUpdatedListener(new RemoteMediaPlayer.OnQueueStatusUpdatedListener() {
@Override
public void onQueueStatusUpdated() {
LOGD(TAG, "RemoteMediaPlayer::onQueueStatusUpdated() is reached");
mMediaStatus = mRemoteMediaPlayer != null ? mRemoteMediaPlayer.getMediaStatus() : null;
if (mMediaStatus != null && mMediaStatus.getQueueItems() != null) {
List<MediaQueueItem> queueItems = mMediaStatus.getQueueItems();
int itemId = mMediaStatus.getCurrentItemId();
MediaQueueItem item = mMediaStatus.getQueueItemById(itemId);
int repeatMode = mMediaStatus.getQueueRepeatMode();
onQueueUpdated(queueItems, item, repeatMode, false);
} else {
onQueueUpdated(null, null, MediaStatus.REPEAT_MODE_REPEAT_OFF, false);
}
}
});
}
try {
LOGD(TAG, "Registering MediaChannel namespace");
Cast.CastApi.setMessageReceivedCallbacks(mApiClient, mRemoteMediaPlayer.getNamespace(), mRemoteMediaPlayer);
} catch (IOException | IllegalStateException e) {
LOGE(TAG, "attachMediaChannel()", e);
}
setUpMediaSession(null);
}
use of com.google.android.gms.cast.RemoteMediaPlayer in project zype-android by zype.
the class VideoCastManager method attachMediaChannel.
private void attachMediaChannel() throws TransientNetworkDisconnectionException, NoConnectionException {
LOGD(TAG, "attachMediaChannel()");
checkConnectivity();
if (mRemoteMediaPlayer == null) {
mRemoteMediaPlayer = new RemoteMediaPlayer();
mRemoteMediaPlayer.setOnStatusUpdatedListener(new RemoteMediaPlayer.OnStatusUpdatedListener() {
@Override
public void onStatusUpdated() {
LOGD(TAG, "RemoteMediaPlayer::onStatusUpdated() is reached");
VideoCastManager.this.onRemoteMediaPlayerStatusUpdated();
}
});
mRemoteMediaPlayer.setOnPreloadStatusUpdatedListener(new RemoteMediaPlayer.OnPreloadStatusUpdatedListener() {
@Override
public void onPreloadStatusUpdated() {
LOGD(TAG, "[preload] RemoteMediaPlayer::onPreloadStatusUpdated() is " + "reached");
VideoCastManager.this.onRemoteMediaPreloadStatusUpdated();
}
});
mRemoteMediaPlayer.setOnMetadataUpdatedListener(new RemoteMediaPlayer.OnMetadataUpdatedListener() {
@Override
public void onMetadataUpdated() {
LOGD(TAG, "RemoteMediaPlayer::onMetadataUpdated() is reached");
VideoCastManager.this.onRemoteMediaPlayerMetadataUpdated();
}
});
mRemoteMediaPlayer.setOnQueueStatusUpdatedListener(new RemoteMediaPlayer.OnQueueStatusUpdatedListener() {
@Override
public void onQueueStatusUpdated() {
LOGD(TAG, "RemoteMediaPlayer::onQueueStatusUpdated() is " + "reached");
mMediaStatus = mRemoteMediaPlayer.getMediaStatus();
if (mMediaStatus != null && mMediaStatus.getQueueItems() != null) {
List<MediaQueueItem> queueItems = mMediaStatus.getQueueItems();
int itemId = mMediaStatus.getCurrentItemId();
MediaQueueItem item = mMediaStatus.getQueueItemById(itemId);
int repeatMode = mMediaStatus.getQueueRepeatMode();
boolean shuffle = false;
onQueueUpdated(queueItems, item, repeatMode, shuffle);
} else {
onQueueUpdated(null, null, MediaStatus.REPEAT_MODE_REPEAT_OFF, false);
}
}
});
}
try {
LOGD(TAG, "Registering MediaChannel namespace");
Cast.CastApi.setMessageReceivedCallbacks(mApiClient, mRemoteMediaPlayer.getNamespace(), mRemoteMediaPlayer);
} catch (IOException | IllegalStateException e) {
LOGE(TAG, "attachMediaChannel()", e);
}
}
use of com.google.android.gms.cast.RemoteMediaPlayer in project AntennaPod by AntennaPod.
the class CastManager method attachMediaChannel.
private void attachMediaChannel() throws TransientNetworkDisconnectionException, NoConnectionException {
Log.d(TAG, "attachMediaChannel()");
checkConnectivity();
if (remoteMediaPlayer == null) {
remoteMediaPlayer = new RemoteMediaPlayer();
remoteMediaPlayer.setOnStatusUpdatedListener(() -> {
Log.d(TAG, "RemoteMediaPlayer::onStatusUpdated() is reached");
CastManager.this.onRemoteMediaPlayerStatusUpdated();
});
remoteMediaPlayer.setOnPreloadStatusUpdatedListener(() -> {
Log.d(TAG, "RemoteMediaPlayer::onPreloadStatusUpdated() is reached");
CastManager.this.onRemoteMediaPreloadStatusUpdated();
});
remoteMediaPlayer.setOnMetadataUpdatedListener(() -> {
Log.d(TAG, "RemoteMediaPlayer::onMetadataUpdated() is reached");
CastManager.this.onRemoteMediaPlayerMetadataUpdated();
});
remoteMediaPlayer.setOnQueueStatusUpdatedListener(() -> {
Log.d(TAG, "RemoteMediaPlayer::onQueueStatusUpdated() is reached");
mediaStatus = remoteMediaPlayer.getMediaStatus();
if (mediaStatus != null && mediaStatus.getQueueItems() != null) {
List<MediaQueueItem> queueItems = mediaStatus.getQueueItems();
int itemId = mediaStatus.getCurrentItemId();
MediaQueueItem item = mediaStatus.getQueueItemById(itemId);
int repeatMode = mediaStatus.getQueueRepeatMode();
onQueueUpdated(queueItems, item, repeatMode, false);
} else {
onQueueUpdated(null, null, MediaStatus.REPEAT_MODE_REPEAT_OFF, false);
}
});
}
try {
Log.d(TAG, "Registering MediaChannel namespace");
Cast.CastApi.setMessageReceivedCallbacks(mApiClient, remoteMediaPlayer.getNamespace(), remoteMediaPlayer);
} catch (IOException | IllegalStateException e) {
Log.e(TAG, "attachMediaChannel()", e);
}
}
Aggregations