当前位置: 首页>>代码示例>>Java>>正文


Java NoConnectionException类代码示例

本文整理汇总了Java中com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException的典型用法代码示例。如果您正苦于以下问题:Java NoConnectionException类的具体用法?Java NoConnectionException怎么用?Java NoConnectionException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NoConnectionException类属于com.google.sample.castcompanionlibrary.cast.exceptions包,在下文中一共展示了NoConnectionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleException

import com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException; //导入依赖的package包/类
/**
 * A utility method to handle a few types of exceptions that are commonly thrown by the cast
 * APIs in this library. It has special treatments for
 * {@link com.google.sample.castcompanionlibrary.cast.exceptions.TransientNetworkDisconnectionException}, {@link com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException} and shows an
 * "Oops" dialog conveying certain messages to the user. The following resource IDs can be used
 * to control the messages that are shown:
 * <p>
 * <ul>
 * <li><code>R.string.connection_lost_retry</code></li>
 * <li><code>R.string.connection_lost</code></li>
 * <li><code>R.string.failed_to_perform_action</code></li>
 * </ul>
 *
 * @param context
 * @param e
 */
public static void handleException(Context context, Exception e) {
    int resourceId = 0;
    if (e instanceof TransientNetworkDisconnectionException) {
        // temporary loss of connectivity
        resourceId = R.string.connection_lost_retry;

    } else if (e instanceof NoConnectionException) {
        // connection gone
        resourceId = R.string.connection_lost;
    } else if (e instanceof RuntimeException ||
            e instanceof IOException ||
            e instanceof CastException) {
        // something more serious happened
        resourceId = R.string.failed_to_perform_action;
    } else {
        // well, who knows!
        resourceId = R.string.failed_to_perform_action;
    }
    if (resourceId > 0) {
        com.google.sample.cast.refplayer.utils.Utils.showOopsDialog(context, resourceId);
    }
}
 
开发者ID:BruGTUG,项目名称:codelab-chromecast,代码行数:39,代码来源:Utils.java

示例2: handleException

import com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException; //导入依赖的package包/类
/**
 * A utility method to handle a few types of exceptions that are commonly thrown by the cast
 * APIs in this library. It has special treatments for
 * {@link TransientNetworkDisconnectionException}, {@link NoConnectionException} and shows an
 * "Oops" dialog conveying certain messages to the user. The following resource IDs can be used
 * to control the messages that are shown:
 * <p>
 * <ul>
 * <li><code>R.string.connection_lost_retry</code></li>
 * <li><code>R.string.connection_lost</code></li>
 * <li><code>R.string.failed_to_perform_action</code></li>
 * </ul>
 *
 * @param context
 * @param e
 */
public static void handleException(Context context, Exception e) {
    int resourceId = 0;
    if (e instanceof TransientNetworkDisconnectionException) {
        // temporary loss of connectivity
        resourceId = R.string.connection_lost_retry;

    } else if (e instanceof NoConnectionException) {
        // connection gone
        resourceId = R.string.connection_lost;
    } else if (e instanceof RuntimeException ||
            e instanceof IOException ||
            e instanceof CastException) {
        // something more serious happened
        resourceId = R.string.failed_to_perform_action;
    } else {
        // well, who knows!
        resourceId = R.string.failed_to_perform_action;
    }
    if (resourceId > 0) {
        com.google.sample.cast.refplayer.utils.Utils.showOopsDialog(context, resourceId);
    }
}
 
开发者ID:BruGTUG,项目名称:codelab-chromecast,代码行数:39,代码来源:Utils.java

示例3: sendDataMessage

import com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException; //导入依赖的package包/类
/**
 * Sends the <code>message</code> on the data channel for the <code>namespace</code>. If fails,
 * it will call <code>onMessageSendFailed</code>
 *
 * @param message
 * @param namespace
 * @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
 * @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,
        TransientNetworkDisconnectionException, NoConnectionException {
    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);
                    }
                }
            });
}
 
开发者ID:BruGTUG,项目名称:codelab-chromecast,代码行数:33,代码来源:DataCastManager.java

示例4: updateMiniController

import com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException; //导入依赖的package包/类
/**
 * Updates the information and state of a MiniController.
 *
 * @throws TransientNetworkDisconnectionException
 * @throws NoConnectionException
 */
private void updateMiniController(IMiniController controller)
        throws TransientNetworkDisconnectionException, NoConnectionException {
    checkConnectivity();
    checkRemoteMediaPlayerAvailable();
    if (mRemoteMediaPlayer.getStreamDuration() > 0 || isRemoteStreamLive()) {
        MediaInfo mediaInfo = getRemoteMediaInformation();
        MediaMetadata mm = mediaInfo.getMetadata();
        controller.setStreamType(mediaInfo.getStreamType());
        controller.setPlaybackStatus(mState, mIdleReason);
        controller.setSubTitle(mContext.getResources().getString(R.string.casting_to_device,
                mDeviceName));
        controller.setTitle(mm.getString(MediaMetadata.KEY_TITLE));
        if (!mm.getImages().isEmpty()) {
            controller.setIcon(mm.getImages().get(0).getUrl());
        }
    }
}
 
开发者ID:BruGTUG,项目名称:codelab-chromecast,代码行数:24,代码来源:VideoCastManager.java

示例5: shouldRemoteUiBeVisible

import com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException; //导入依赖的package包/类
/**
 * A helper method to determine if, given a player state and an idle reason (if the state is
 * idle) will warrant having a UI for remote presentation of the remote content.
 *
 * @param state
 * @param idleReason
 * @return
 * @throws TransientNetworkDisconnectionException
 * @throws NoConnectionException
 */
public boolean shouldRemoteUiBeVisible(int state, int idleReason)
        throws TransientNetworkDisconnectionException,
        NoConnectionException {
    switch (state) {
        case MediaStatus.PLAYER_STATE_PLAYING:
        case MediaStatus.PLAYER_STATE_PAUSED:
        case MediaStatus.PLAYER_STATE_BUFFERING:
            return true;
        case MediaStatus.PLAYER_STATE_IDLE:
            if (!isRemoteStreamLive()) {
                return false;
            }
            return idleReason == MediaStatus.IDLE_REASON_CANCELED;
        default:
            break;
    }
    return false;
}
 
开发者ID:BruGTUG,项目名称:codelab-chromecast,代码行数:29,代码来源:VideoCastManager.java

示例6: setMute

import com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException; //导入依赖的package包/类
/**
 * Mutes or un-mutes the volume. It internally determines if this should be done for
 * <code>stream</code> or <code>device</code> volume.
 *
 * @param mute
 * @throws CastException
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void setMute(boolean mute) throws CastException, TransientNetworkDisconnectionException,
        NoConnectionException {
    checkConnectivity();
    if (mVolumeType == VolumeType.STREAM) {
        checkRemoteMediaPlayerAvailable();
        mRemoteMediaPlayer.setStreamMute(mApiClient, mute);
    } else {
        try {
            Cast.CastApi.setMute(mApiClient, mute);
        } catch (Exception e) {
            LOGE(TAG, "Failed to set volume", e);
            throw new CastException("Failed to set volume", e);
        }
    }
}
 
开发者ID:BruGTUG,项目名称:codelab-chromecast,代码行数:25,代码来源:VideoCastManager.java

示例7: play

import com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException; //导入依赖的package包/类
/**
 * Resumes the playback from where it was left (can be the beginning).
 *
 * @param customData Optional {@link JSONObject} data to be passed to the cast device
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void play(JSONObject customData) throws
        TransientNetworkDisconnectionException, NoConnectionException {
    LOGD(TAG, "play(customData)");
    checkConnectivity();
    if (mRemoteMediaPlayer == null) {
        LOGE(TAG, "Trying to play a video with no active media session");
        throw new NoConnectionException();
    }
    mRemoteMediaPlayer.play(mApiClient, customData)
            .setResultCallback(new ResultCallback<MediaChannelResult>() {

                @Override
                public void onResult(MediaChannelResult result) {
                    if (!result.getStatus().isSuccess()) {
                        onFailed(R.string.failed_to_play, result.getStatus().getStatusCode());
                    }
                }

            });
}
 
开发者ID:BruGTUG,项目名称:codelab-chromecast,代码行数:28,代码来源:VideoCastManager.java

示例8: stop

import com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException; //导入依赖的package包/类
/**
 * Stops the playback of media/stream
 *
 * @param customData Optional {@link JSONObject}
 * @throws TransientNetworkDisconnectionException
 * @throws NoConnectionException
 */
public void stop(JSONObject customData) throws
        TransientNetworkDisconnectionException, NoConnectionException {
    LOGD(TAG, "stop()");
    checkConnectivity();
    if (mRemoteMediaPlayer == null) {
        LOGE(TAG, "Trying to stop a stream with no active media session");
        throw new NoConnectionException();
    }
    mRemoteMediaPlayer.stop(mApiClient, customData).setResultCallback(
            new ResultCallback<MediaChannelResult>() {

                @Override
                public void onResult(MediaChannelResult result) {
                    if (!result.getStatus().isSuccess()) {
                        onFailed(R.string.failed_to_stop, result.getStatus().getStatusCode());
                    }
                }

            }
    );
}
 
开发者ID:BruGTUG,项目名称:codelab-chromecast,代码行数:29,代码来源:VideoCastManager.java

示例9: pause

import com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException; //导入依赖的package包/类
/**
 * Pauses the playback.
 *
 * @param customData Optional {@link JSONObject} data to be passed to the cast device
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void pause(JSONObject customData) throws
        TransientNetworkDisconnectionException, NoConnectionException {
    LOGD(TAG, "attempting to pause media");
    checkConnectivity();
    if (mRemoteMediaPlayer == null) {
        LOGE(TAG, "Trying to pause a video with no active media session");
        throw new NoConnectionException();
    }
    mRemoteMediaPlayer.pause(mApiClient, customData)
            .setResultCallback(new ResultCallback<MediaChannelResult>() {

                @Override
                public void onResult(MediaChannelResult result) {
                    if (!result.getStatus().isSuccess()) {
                        onFailed(R.string.failed_to_pause, result.getStatus().getStatusCode());
                    }
                }

            });
}
 
开发者ID:BruGTUG,项目名称:codelab-chromecast,代码行数:28,代码来源:VideoCastManager.java

示例10: seek

import com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException; //导入依赖的package包/类
/**
 * Seeks to the given point without changing the state of the player, i.e. after seek is
 * completed, it resumes what it was doing before the start of seek.
 *
 * @param position in milliseconds
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void seek(int position) throws TransientNetworkDisconnectionException,
        NoConnectionException {
    LOGD(TAG, "attempting to seek media");
    checkConnectivity();
    if (mRemoteMediaPlayer == null) {
        LOGE(TAG, "Trying to seek a video with no active media session");
        throw new NoConnectionException();
    }
    mRemoteMediaPlayer.seek(mApiClient,
            position,
            RemoteMediaPlayer.RESUME_STATE_UNCHANGED).
            setResultCallback(new ResultCallback<MediaChannelResult>() {

                @Override
                public void onResult(MediaChannelResult result) {
                    if (!result.getStatus().isSuccess()) {
                        onFailed(R.string.failed_seek, result.getStatus().getStatusCode());
                    }
                }

            });
}
 
开发者ID:BruGTUG,项目名称:codelab-chromecast,代码行数:31,代码来源:VideoCastManager.java

示例11: seekAndPlay

import com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException; //导入依赖的package包/类
/**
 * Seeks to the given point and starts playback regardless of the starting state.
 *
 * @param position in milliseconds
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void seekAndPlay(int position) throws TransientNetworkDisconnectionException,
        NoConnectionException {
    LOGD(TAG, "attempting to seek media");
    checkConnectivity();
    if (mRemoteMediaPlayer == null) {
        LOGE(TAG, "Trying to seekAndPlay a video with no active media session");
        throw new NoConnectionException();
    }
    ResultCallback<MediaChannelResult> resultCallback =
            new ResultCallback<MediaChannelResult>() {

                @Override
                public void onResult(MediaChannelResult result) {
                    if (!result.getStatus().isSuccess()) {
                        onFailed(R.string.failed_seek, result.getStatus().getStatusCode());
                    }
                }

            };
    mRemoteMediaPlayer.seek(mApiClient,
            position,
            RemoteMediaPlayer.RESUME_STATE_PLAY).setResultCallback(resultCallback);
}
 
开发者ID:BruGTUG,项目名称:codelab-chromecast,代码行数:31,代码来源:VideoCastManager.java

示例12: togglePlayback

import com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException; //导入依赖的package包/类
/**
 * Toggles the playback of the movie.
 *
 * @throws CastException
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void togglePlayback() throws CastException, TransientNetworkDisconnectionException,
        NoConnectionException {
    checkConnectivity();
    boolean isPlaying = isRemoteMoviePlaying();
    if (isPlaying) {
        pause();
    } else {
        if (mState == MediaStatus.PLAYER_STATE_IDLE
                && mIdleReason == MediaStatus.IDLE_REASON_FINISHED) {
            loadMedia(getRemoteMediaInformation(), true, 0);
        } else {
            play();
        }
    }
}
 
开发者ID:BruGTUG,项目名称:codelab-chromecast,代码行数:23,代码来源:VideoCastManager.java

示例13: sendDataMessage

import com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException; //导入依赖的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 &gt; 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.
 *
 * @param 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());
                    }
                }
            });
}
 
开发者ID:BruGTUG,项目名称:codelab-chromecast,代码行数:31,代码来源:VideoCastManager.java

示例14: stopApplication

import com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException; //导入依赖的package包/类
/**
 * Stops the application on the receiver device.
 *
 * @throws IllegalStateException
 * @throws IOException
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public void stopApplication() throws IllegalStateException, IOException,
        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");
                    }
                }
            });
}
 
开发者ID:BruGTUG,项目名称:codelab-chromecast,代码行数:28,代码来源:BaseCastManager.java

示例15: pause

import com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException; //导入依赖的package包/类
@Override
public void pause() {
    try {
        if (mCastManager.isRemoteMediaLoaded()) {
            mCastManager.pause();
            mCurrentPosition = (int) mCastManager.getCurrentMediaPosition();
        } else {
            loadMedia(mCurrentMediaId, false);
        }
    } catch (JSONException | CastException | TransientNetworkDisconnectionException
            | NoConnectionException e) {
        LogHelper.e(TAG, e, "Exception pausing cast playback");
        if (mCallback != null) {
            mCallback.onError(e.getMessage());
        }
    }
}
 
开发者ID:ErNaveen,项目名称:UniversalMusicPlayer,代码行数:18,代码来源:CastPlayback.java


注:本文中的com.google.sample.castcompanionlibrary.cast.exceptions.NoConnectionException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。