use of com.google.android.gms.cast.CastDevice in project Shuttle by timusus.
the class BaseCastManager method reconnectSessionIfPossibleInternal.
private void reconnectSessionIfPossibleInternal(RouteInfo theRoute) {
if (isConnected()) {
return;
}
String sessionId = mPreferenceAccessor.getStringFromPreference(PREFS_KEY_SESSION_ID);
String routeId = mPreferenceAccessor.getStringFromPreference(PREFS_KEY_ROUTE_ID);
LOGD(TAG, "reconnectSessionIfPossible() Retrieved from preferences: " + "sessionId=" + sessionId + ", routeId=" + routeId);
if (sessionId == null || routeId == null) {
return;
}
setReconnectionStatus(RECONNECTION_STATUS_IN_PROGRESS);
CastDevice device = CastDevice.getFromBundle(theRoute.getExtras());
if (device != null) {
LOGD(TAG, "trying to acquire Cast Client for " + device);
onDeviceSelected(device, theRoute);
}
}
use of com.google.android.gms.cast.CastDevice in project Shuttle by timusus.
the class CastMediaRouterCallback method onRouteSelected.
@Override
public void onRouteSelected(MediaRouter router, RouteInfo info) {
LOGD(TAG, "onRouteSelected: info=" + info);
if (mCastManager.getReconnectionStatus() == BaseCastManager.RECONNECTION_STATUS_FINALIZED) {
mCastManager.setReconnectionStatus(BaseCastManager.RECONNECTION_STATUS_INACTIVE);
mCastManager.cancelReconnectionTask();
return;
}
mCastManager.getPreferenceAccessor().saveStringToPreference(BaseCastManager.PREFS_KEY_ROUTE_ID, info.getId());
CastDevice device = CastDevice.getFromBundle(info.getExtras());
mCastManager.onDeviceSelected(device, info);
LOGD(TAG, "onRouteSelected: mSelectedDevice=" + (device != null ? device.getFriendlyName() : "Null"));
}
use of com.google.android.gms.cast.CastDevice in project Shuttle by timusus.
the class VideoCastManager method attachDataChannel.
/*
* If a data namespace was provided when initializing this class, we set things up for a data
* channel
*
* @throws NoConnectionException
* @throws TransientNetworkDisconnectionException
*/
private void attachDataChannel() throws TransientNetworkDisconnectionException, NoConnectionException {
if (TextUtils.isEmpty(mDataNamespace)) {
return;
}
if (mDataChannel != null) {
return;
}
checkConnectivity();
mDataChannel = new MessageReceivedCallback() {
@Override
public void onMessageReceived(CastDevice castDevice, String namespace, String message) {
for (VideoCastConsumer consumer : mVideoConsumers) {
consumer.onDataMessageReceived(message);
}
}
};
try {
Cast.CastApi.setMessageReceivedCallbacks(mApiClient, mDataNamespace, mDataChannel);
} catch (IOException | IllegalStateException e) {
LOGE(TAG, "attachDataChannel()", e);
}
}
use of com.google.android.gms.cast.CastDevice in project Shuttle by timusus.
the class CastMediaRouterCallback method onRouteAdded.
@Override
public void onRouteAdded(MediaRouter router, RouteInfo routeInfo) {
if (!router.getDefaultRoute().equals(routeInfo)) {
notifyRouteAvailabilityChangedIfNeeded(router);
mCastManager.onCastDeviceDetected(routeInfo);
}
if (mCastManager.getReconnectionStatus() == BaseCastManager.RECONNECTION_STATUS_STARTED) {
String routeId = mCastManager.getPreferenceAccessor().getStringFromPreference(BaseCastManager.PREFS_KEY_ROUTE_ID);
if (routeInfo.getId().equals(routeId)) {
// we found the route, so lets go with that
LOGD(TAG, "onRouteAdded: Attempting to recover a session with info=" + routeInfo);
mCastManager.setReconnectionStatus(BaseCastManager.RECONNECTION_STATUS_IN_PROGRESS);
CastDevice device = CastDevice.getFromBundle(routeInfo.getExtras());
LOGD(TAG, "onRouteAdded: Attempting to recover a session with device: " + (device != null ? device.getFriendlyName() : "Null"));
mCastManager.onDeviceSelected(device, routeInfo);
}
}
}
Aggregations