本文整理汇总了Java中com.google.android.gms.cast.Cast类的典型用法代码示例。如果您正苦于以下问题:Java Cast类的具体用法?Java Cast怎么用?Java Cast使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Cast类属于com.google.android.gms.cast包,在下文中一共展示了Cast类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onResult
import com.google.android.gms.cast.Cast; //导入依赖的package包/类
@Override
public void onResult(Cast.ApplicationConnectionResult result) {
if (mState != STATE_LAUNCHING_APPLICATION
&& mState != STATE_API_CONNECTION_SUSPENDED) {
throwInvalidState();
}
Status status = result.getStatus();
if (!status.isSuccess()) {
Log.e(TAG, "Launch application failed with status: %s, %d, %s",
mSource.getApplicationId(), status.getStatusCode(), status.getStatusMessage());
reportError();
}
mState = STATE_LAUNCH_SUCCEEDED;
reportSuccess(result);
}
示例2: reportSuccess
import com.google.android.gms.cast.Cast; //导入依赖的package包/类
private void reportSuccess(Cast.ApplicationConnectionResult result) {
if (mState != STATE_LAUNCH_SUCCEEDED) throwInvalidState();
CastSession session = new CastSessionImpl(
mApiClient,
result.getSessionId(),
result.getApplicationMetadata(),
result.getApplicationStatus(),
mSink.getDevice(),
mOrigin,
mTabId,
mIsIncognito,
mSource,
mRouteProvider);
mCastListener.setSession(session);
mRouteProvider.onSessionCreated(session);
terminate();
}
示例3: updateSessionStatus
import com.google.android.gms.cast.Cast; //导入依赖的package包/类
@Override
public void updateSessionStatus() {
if (isApiClientInvalid()) return;
try {
mApplicationStatus = Cast.CastApi.getApplicationStatus(mApiClient);
mApplicationMetadata = Cast.CastApi.getApplicationMetadata(mApiClient);
updateNamespaces();
mMessageHandler.broadcastClientMessage(
"update_session", mMessageHandler.buildSessionMessage());
} catch (IllegalStateException e) {
Log.e(TAG, "Can't get application status", e);
}
}
示例4: addNamespace
import com.google.android.gms.cast.Cast; //导入依赖的package包/类
/**
* Adds a channel with the given {@code namespace} and registers {@link DataCastManager} as
* the callback receiver. If the namespace is already registered, this returns
* <code>false</code>, otherwise returns <code>true</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 boolean addNamespace(String namespace) throws
TransientNetworkDisconnectionException, NoConnectionException {
checkConnectivity();
if (TextUtils.isEmpty(namespace)) {
throw new IllegalArgumentException("namespace cannot be empty");
}
if (mNamespaceList.contains(namespace)) {
LOGD(TAG, "Ignoring to add a namespace that is already added.");
return false;
}
try {
Cast.CastApi.setMessageReceivedCallbacks(mApiClient, namespace, this);
mNamespaceList.add(namespace);
return true;
} catch (IOException | IllegalStateException e) {
LOGE(TAG, String.format("addNamespace(%s)", namespace), e);
}
return false;
}
示例5: removeNamespace
import com.google.android.gms.cast.Cast; //导入依赖的package包/类
/**
* Unregisters a namespace. If namespace is not already registered, it returns
* <code>false</code>, otherwise a successful removal returns <code>true</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 boolean removeNamespace(String namespace) throws TransientNetworkDisconnectionException,
NoConnectionException {
checkConnectivity();
if (TextUtils.isEmpty(namespace)) {
throw new IllegalArgumentException("namespace cannot be empty");
}
if (!mNamespaceList.contains(namespace)) {
LOGD(TAG, "Ignoring to remove a namespace that is not registered.");
return false;
}
try {
Cast.CastApi.removeMessageReceivedCallbacks(mApiClient, namespace);
mNamespaceList.remove(namespace);
return true;
} catch (IOException | IllegalStateException e) {
LOGE(TAG, String.format("removeNamespace(%s)", namespace), e);
}
return false;
}
示例6: sendDataMessage
import com.google.android.gms.cast.Cast; //导入依赖的package包/类
/**
* Sends the <code>message</code> on the data channel for the <code>namespace</code>. If fails,
* it will call <code>onMessageSendFailed</code>
*
* @throws IllegalArgumentException If the the message is null, empty, or too long; or if the
* namespace is null or too long.
* @throws IllegalStateException If there is no active service connection.
* @throws IOException
*/
public void sendDataMessage(String message, String namespace)
throws IllegalArgumentException, IllegalStateException, IOException {
checkConnectivity();
if (TextUtils.isEmpty(namespace)) {
throw new IllegalArgumentException("namespace cannot be empty");
}
Cast.CastApi.sendMessage(mApiClient, namespace, message).
setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status result) {
if (!result.isSuccess()) {
DataCastManager.this.onMessageSendFailed(result);
}
}
});
}
示例7: onApplicationStatusChanged
import com.google.android.gms.cast.Cast; //导入依赖的package包/类
public void onApplicationStatusChanged() {
String appStatus;
if (!isConnected()) {
return;
}
try {
appStatus = Cast.CastApi.getApplicationStatus(mApiClient);
LOGD(TAG, "onApplicationStatusChanged() reached: " + appStatus);
for (DataCastConsumer consumer : mDataConsumers) {
consumer.onApplicationStatusChanged(appStatus);
}
} catch (IllegalStateException e) {
LOGE(TAG, "onApplicationStatusChanged(): Failed", e);
}
}
示例8: sendDataMessage
import com.google.android.gms.cast.Cast; //导入依赖的package包/类
/**
* Sends the <code>message</code> on the data channel for the namespace that was provided
* during the initialization of this class. If <code>messageId > 0</code>, then it has to be
* a unique identifier for the message; this id will be returned if an error occurs. If
* <code>messageId == 0</code>, then an auto-generated unique identifier will be created and
* returned for the message.
*
* @throws IllegalStateException If the namespace is empty or null
* @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 void sendDataMessage(String message) throws TransientNetworkDisconnectionException,
NoConnectionException {
if (TextUtils.isEmpty(mDataNamespace)) {
throw new IllegalStateException("No Data Namespace is configured");
}
checkConnectivity();
Cast.CastApi.sendMessage(mApiClient, mDataNamespace, message)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status result) {
if (!result.isSuccess()) {
VideoCastManager.this.onMessageSendFailed(result.getStatusCode());
}
}
});
}
示例9: removeDataChannel
import com.google.android.gms.cast.Cast; //导入依赖的package包/类
/**
* Remove the custom data channel, if any. It returns <code>true</code> if it succeeds
* otherwise if it encounters an error or if no connection exists or if no custom data channel
* exists, then it returns <code>false</code>
*/
public boolean removeDataChannel() {
if (TextUtils.isEmpty(mDataNamespace)) {
return false;
}
try {
if (mApiClient != null) {
Cast.CastApi.removeMessageReceivedCallbacks(mApiClient, mDataNamespace);
}
mDataChannel = null;
mPreferenceAccessor.saveStringToPreference(PREFS_KEY_CAST_CUSTOM_DATA_NAMESPACE, null);
return true;
} catch (IOException | IllegalStateException e) {
LOGE(TAG, "removeDataChannel() failed to remove namespace " + mDataNamespace, e);
}
return false;
}
示例10: setDevice
import com.google.android.gms.cast.Cast; //导入依赖的package包/类
private void setDevice(CastDevice device) {
mSelectedCastDevice = device;
mDeviceName = mSelectedCastDevice.getFriendlyName();
if (mApiClient == null) {
LOGD(TAG, "acquiring a connection to Google Play services for " + mSelectedCastDevice);
Cast.CastOptions.Builder apiOptionsBuilder = getCastOptionBuilder(mSelectedCastDevice);
mApiClient = new GoogleApiClient.Builder(mContext)
.addApi(Cast.API, apiOptionsBuilder.build())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mApiClient.connect();
} else if (!mApiClient.isConnected() && !mApiClient.isConnecting()) {
mApiClient.connect();
}
}
示例11: stopApplication
import com.google.android.gms.cast.Cast; //导入依赖的package包/类
/**
* Stops the application on the receiver device.
*
* @throws NoConnectionException
* @throws TransientNetworkDisconnectionException
*/
public final void stopApplication()
throws TransientNetworkDisconnectionException, NoConnectionException {
checkConnectivity();
Cast.CastApi.stopApplication(mApiClient, mSessionId).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status result) {
if (!result.isSuccess()) {
LOGD(TAG, "stopApplication -> onResult: stopping "
+ "application failed");
onApplicationStopFailed(result.getStatusCode());
} else {
LOGD(TAG, "stopApplication -> onResult Stopped application "
+ "successfully");
}
}
});
}
示例12: connect
import com.google.android.gms.cast.Cast; //导入依赖的package包/类
@Override
public void connect(final ResponseListener<Object> listener) {
if (castServiceChannel != null) {
disconnectFromWebApp();
}
castServiceChannel = new CastServiceChannel(launchSession.getAppId(), this);
try {
Cast.CastApi.setMessageReceivedCallbacks(service.getApiClient(),
castServiceChannel.getNamespace(),
castServiceChannel);
Util.postSuccess(listener, null);
} catch (IOException e) {
castServiceChannel = null;
Util.postError(listener, new ServiceCommandError(0, "Failed to create channel", null));
}
}
示例13: sendMessage
import com.google.android.gms.cast.Cast; //导入依赖的package包/类
@Override
public void sendMessage(String message, final ResponseListener<Object> listener) {
if (message == null) {
Util.postError(listener, new ServiceCommandError(0, "Cannot send null message", null));
return;
}
if (castServiceChannel == null) {
Util.postError(listener, new ServiceCommandError(0, "Cannot send a message to the web app without first connecting", null));
return;
}
Cast.CastApi.sendMessage(service.getApiClient(), castServiceChannel.getNamespace(), message).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status result) {
if (result.isSuccess()) {
Util.postSuccess(listener, null);
}
else {
Util.postError(listener, new ServiceCommandError(result.getStatusCode(), result.toString(), result));
}
}
});
}
示例14: joinSession
import com.google.android.gms.cast.Cast; //导入依赖的package包/类
private void joinSession() {
try {
Cast.CastApi
.joinApplication(mApiClient,
CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID,
mSessionId)
.setResultCallback(
new ResultCallback<Cast.ApplicationConnectionResult>() {
@Override
public void onResult(
@NonNull final Cast.ApplicationConnectionResult result) {
Status status = result.getStatus();
if (status.isSuccess()) {
Log.i(TAG, "Joined session: " + mRouteInfo.getName());
setApplicationStarted(true);
mMediaRouter.selectRoute(mRouteInfo);
connectRemoteMediaPlayer();
} else {
teardown();
}
}
});
} catch (Exception e) {
Log.e(TAG, "Failed to join application", e);
}
}
示例15: connectRemoteMediaPlayer
import com.google.android.gms.cast.Cast; //导入依赖的package包/类
private void connectRemoteMediaPlayer() {
try {
Cast.CastApi.setMessageReceivedCallbacks(mApiClient, mRemoteMediaPlayer.getNamespace(),
mRemoteMediaPlayer);
} catch (IOException e) {
Log.e(TAG, "Exception while creating media channel", e);
}
mRemoteMediaPlayer
.requestStatus(mApiClient)
.setResultCallback(
new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {
@Override
public void onResult(
@NonNull final RemoteMediaPlayer.MediaChannelResult result) {
if (!result.getStatus().isSuccess()) {
Log.e(TAG, "Failed to request status.");
}
}
});
}