use of com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException in project Shuttle by timusus.
the class BaseCastManager method disconnectDevice.
/**
* Disconnects from the connected device.
*
* @param stopAppOnExit If {@code true}, the application running on the cast device will be
* stopped when disconnected.
* @param clearPersistedConnectionData If {@code true}, the persisted connection information
* will be cleared as part of this call.
* @param setDefaultRoute If {@code true}, after disconnection, the selected route will be set
* to the Default Route.
*/
public final void disconnectDevice(boolean stopAppOnExit, boolean clearPersistedConnectionData, boolean setDefaultRoute) {
LOGD(TAG, "disconnectDevice(" + clearPersistedConnectionData + "," + setDefaultRoute + ")");
if (mSelectedCastDevice == null) {
return;
}
mSelectedCastDevice = null;
mDeviceName = null;
String message = "disconnectDevice() Disconnect Reason: ";
int reason;
if (mConnectionSuspended) {
message += "Connectivity lost";
reason = DISCONNECT_REASON_CONNECTIVITY;
} else {
switch(mApplicationErrorCode) {
case CastStatusCodes.APPLICATION_NOT_RUNNING:
message += "App was taken over or not available anymore";
reason = DISCONNECT_REASON_APP_NOT_RUNNING;
break;
case NO_APPLICATION_ERROR:
message += "Intentional disconnect";
reason = DISCONNECT_REASON_EXPLICIT;
break;
default:
message += "Other";
reason = DISCONNECT_REASON_OTHER;
}
}
LOGD(TAG, message);
for (BaseCastConsumer consumer : mBaseCastConsumers) {
consumer.onDisconnectionReason(reason);
}
LOGD(TAG, "mConnectionSuspended: " + mConnectionSuspended);
if (!mConnectionSuspended && clearPersistedConnectionData) {
clearPersistedConnectionInfo(CLEAR_ALL);
stopReconnectionService();
}
try {
if ((isConnected() || isConnecting()) && stopAppOnExit) {
LOGD(TAG, "Calling stopApplication");
stopApplication();
}
} catch (NoConnectionException | TransientNetworkDisconnectionException e) {
LOGE(TAG, "Failed to stop the application after disconnecting route", e);
}
onDeviceUnselected();
if (mApiClient != null) {
// will throw an exception
if (mApiClient.isConnected()) {
LOGD(TAG, "Trying to disconnect");
mApiClient.disconnect();
}
if ((mMediaRouter != null) && setDefaultRoute) {
LOGD(TAG, "disconnectDevice(): Setting route to default");
mMediaRouter.selectRoute(mMediaRouter.getDefaultRoute());
}
mApiClient = null;
}
mSessionId = null;
onDisconnected(stopAppOnExit, clearPersistedConnectionData, setDefaultRoute);
}
use of com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException in project AntennaPod by AntennaPod.
the class CastManager method getRemoteMediaUrl.
/**
* Returns the url for the media that is currently playing on the remote device. If there is no
* connection, this will return <code>null</code>.
*
* @throws NoConnectionException If no connectivity to the device exists
* @throws TransientNetworkDisconnectionException If framework is still trying to recover from
* a possibly transient loss of network
*/
public String getRemoteMediaUrl() throws TransientNetworkDisconnectionException, NoConnectionException {
checkConnectivity();
if (remoteMediaPlayer != null && remoteMediaPlayer.getMediaInfo() != null) {
MediaInfo info = remoteMediaPlayer.getMediaInfo();
remoteMediaPlayer.getMediaStatus().getPlayerState();
return info.getContentId();
}
throw new NoConnectionException();
}
use of com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException in project AntennaPod by AntennaPod.
the class RemotePSMP method playMediaObject.
/**
* Internal implementation of playMediaObject. This method has an additional parameter that allows the caller to force a media player reset even if
* the given playable parameter is the same object as the currently playing media.
*
* @see #playMediaObject(de.danoeh.antennapod.core.util.playback.Playable, boolean, boolean, boolean)
*/
private void playMediaObject(@NonNull final Playable playable, final boolean forceReset, final boolean stream, final boolean startWhenPrepared, final boolean prepareImmediately) {
if (!CastUtils.isCastable(playable)) {
Log.d(TAG, "media provided is not compatible with cast device");
callback.onMediaPlayerInfo(CAST_ERROR_PRIORITY_HIGH, R.string.cast_not_castable);
Playable nextPlayable = playable;
do {
nextPlayable = callback.getNextInQueue(nextPlayable);
} while (nextPlayable != null && !CastUtils.isCastable(nextPlayable));
if (nextPlayable != null) {
playMediaObject(nextPlayable, forceReset, stream, startWhenPrepared, prepareImmediately);
}
return;
}
if (media != null) {
if (!forceReset && media.getIdentifier().equals(playable.getIdentifier()) && playerStatus == PlayerStatus.PLAYING) {
// episode is already playing -> ignore method call
Log.d(TAG, "Method call to playMediaObject was ignored: media file already playing.");
return;
} else {
// set temporarily to pause in order to update list with current position
boolean isPlaying = playerStatus == PlayerStatus.PLAYING;
int position = media.getPosition();
try {
isPlaying = castMgr.isRemoteMediaPlaying();
position = (int) castMgr.getCurrentMediaPosition();
} catch (TransientNetworkDisconnectionException | NoConnectionException e) {
Log.e(TAG, "Unable to determine whether media was playing, falling back to stored player status", e);
}
if (isPlaying) {
callback.onPlaybackPause(media, position);
}
if (!media.getIdentifier().equals(playable.getIdentifier())) {
final Playable oldMedia = media;
callback.onPostPlayback(oldMedia, false, false, true);
}
setPlayerStatus(PlayerStatus.INDETERMINATE, null);
}
}
this.media = playable;
remoteMedia = remoteVersion(playable);
this.mediaType = media.getMediaType();
this.startWhenPrepared.set(startWhenPrepared);
setPlayerStatus(PlayerStatus.INITIALIZING, media);
try {
media.loadMetadata();
callback.onMediaChanged(true);
setPlayerStatus(PlayerStatus.INITIALIZED, media);
if (prepareImmediately) {
prepare();
}
} catch (Playable.PlayableException e) {
Log.e(TAG, "Error while loading media metadata", e);
setPlayerStatus(PlayerStatus.STOPPED, null);
}
}
Aggregations