Search in sources :

Example 1 with MediaSessionStatus

use of android.support.v7.media.MediaSessionStatus in project cw-omnibus by commonsguy.

the class PlaybackFragment method play.

private void play() {
    logToTranscript(getActivity().getString(R.string.play_requested));
    ItemActionCallback playCB = new ItemActionCallback() {

        @Override
        public void onResult(Bundle data, String sessionId, MediaSessionStatus sessionStatus, String itemId, MediaItemStatus itemStatus) {
            logToTranscript(getActivity().getString(R.string.playing));
            isPlaying = true;
            getActivity().supportInvalidateOptionsMenu();
        }

        @Override
        public void onError(String error, int code, Bundle data) {
            logToTranscript(getActivity().getString(R.string.play_error) + error);
        }
    };
    client.play(Uri.parse("http://misc.commonsware.com/ed_hd_512kb.mp4"), "video/mp4", null, 0, null, playCB);
}
Also used : MediaSessionStatus(android.support.v7.media.MediaSessionStatus) Bundle(android.os.Bundle) ItemActionCallback(android.support.v7.media.RemotePlaybackClient.ItemActionCallback) MediaItemStatus(android.support.v7.media.MediaItemStatus)

Example 2 with MediaSessionStatus

use of android.support.v7.media.MediaSessionStatus in project cw-omnibus by commonsguy.

the class PlaybackFragment method connect.

private void connect(MediaRouter.RouteInfo route) {
    client = new RemotePlaybackClient(getActivity().getApplication(), route);
    if (client.isRemotePlaybackSupported()) {
        logToTranscript(getActivity().getString(R.string.connected));
        if (client.isSessionManagementSupported()) {
            client.startSession(null, new SessionActionCallback() {

                @Override
                public void onResult(Bundle data, String sessionId, MediaSessionStatus sessionStatus) {
                    logToTranscript(getActivity().getString(R.string.session_started));
                    getActivity().supportInvalidateOptionsMenu();
                }

                @Override
                public void onError(String error, int code, Bundle data) {
                    logToTranscript(getActivity().getString(R.string.session_failed));
                }
            });
        } else {
            getActivity().supportInvalidateOptionsMenu();
        }
    } else {
        logToTranscript(getActivity().getString(R.string.remote_playback_not_supported));
        client = null;
    }
}
Also used : RemotePlaybackClient(android.support.v7.media.RemotePlaybackClient) MediaSessionStatus(android.support.v7.media.MediaSessionStatus) SessionActionCallback(android.support.v7.media.RemotePlaybackClient.SessionActionCallback) Bundle(android.os.Bundle)

Example 3 with MediaSessionStatus

use of android.support.v7.media.MediaSessionStatus in project cw-omnibus by commonsguy.

the class PlaybackFragment method connect.

private void connect(MediaRouter.RouteInfo route) {
    client = new RemotePlaybackClient(getActivity().getApplication(), route);
    if (client.isRemotePlaybackSupported()) {
        logToTranscript(getActivity().getString(R.string.connected));
        if (client.isSessionManagementSupported()) {
            client.startSession(null, new SessionActionCallback() {

                @Override
                public void onResult(Bundle data, String sessionId, MediaSessionStatus sessionStatus) {
                    logToTranscript(getActivity().getString(R.string.session_started));
                    updateMenu();
                }

                @Override
                public void onError(String error, int code, Bundle data) {
                    logToTranscript(getActivity().getString(R.string.session_failed));
                }
            });
        } else {
            getActivity().supportInvalidateOptionsMenu();
        }
    } else {
        logToTranscript(getActivity().getString(R.string.remote_playback_not_supported));
        client = null;
    }
}
Also used : RemotePlaybackClient(android.support.v7.media.RemotePlaybackClient) MediaSessionStatus(android.support.v7.media.MediaSessionStatus) SessionActionCallback(android.support.v7.media.RemotePlaybackClient.SessionActionCallback) Bundle(android.os.Bundle)

Example 4 with MediaSessionStatus

use of android.support.v7.media.MediaSessionStatus in project cw-omnibus by commonsguy.

the class PlaybackFragment method play.

private void play() {
    logToTranscript(getActivity().getString(R.string.play_requested));
    ItemActionCallback playCB = new ItemActionCallback() {

        @Override
        public void onResult(Bundle data, String sessionId, MediaSessionStatus sessionStatus, String itemId, MediaItemStatus itemStatus) {
            logToTranscript(getActivity().getString(R.string.playing));
            isPlaying = true;
            updateMenu();
        }

        @Override
        public void onError(String error, int code, Bundle data) {
            logToTranscript(getActivity().getString(R.string.play_error) + error);
        }
    };
    client.play(Uri.parse("http://misc.commonsware.com/ed_hd_512kb.mp4"), "video/mp4", null, 0, null, playCB);
}
Also used : MediaSessionStatus(android.support.v7.media.MediaSessionStatus) Bundle(android.os.Bundle) ItemActionCallback(android.support.v7.media.RemotePlaybackClient.ItemActionCallback) MediaItemStatus(android.support.v7.media.MediaItemStatus)

Example 5 with MediaSessionStatus

use of android.support.v7.media.MediaSessionStatus in project AndroidChromium by JackyAndroid.

the class DefaultMediaRouteController method processSessionStatusBundle.

private void processSessionStatusBundle(Bundle statusBundle) {
    MediaSessionStatus status = MediaSessionStatus.fromBundle(statusBundle.getBundle(MediaControlIntent.EXTRA_SESSION_STATUS));
    int sessionState = status.getSessionState();
    // If no change do nothing
    if (sessionState == mSessionState)
        return;
    mSessionState = sessionState;
    switch(sessionState) {
        case MediaSessionStatus.SESSION_STATE_ACTIVE:
            if (mLocalVideoUri != null) {
                startPlayback(mPreferredTitle, mStartPositionMillis);
            }
            break;
        case MediaSessionStatus.SESSION_STATE_ENDED:
        case MediaSessionStatus.SESSION_STATE_INVALIDATED:
            for (UiListener listener : getUiListeners()) {
                listener.onPlaybackStateChanged(PlayerState.INVALIDATED);
            }
            if (getMediaStateListener() != null) {
                getMediaStateListener().onPlaybackStateChanged(PlayerState.INVALIDATED);
            }
            // Record the remaining time UMA first, otherwise the playback state will be cleared
            // in release().
            recordRemainingTimeUMA();
            // Set the current session id to null so we don't send the stop intent.
            mCurrentSessionId = null;
            release();
            break;
        default:
            break;
    }
}
Also used : MediaSessionStatus(android.support.v7.media.MediaSessionStatus)

Aggregations

MediaSessionStatus (android.support.v7.media.MediaSessionStatus)6 Bundle (android.os.Bundle)4 MediaItemStatus (android.support.v7.media.MediaItemStatus)2 RemotePlaybackClient (android.support.v7.media.RemotePlaybackClient)2 ItemActionCallback (android.support.v7.media.RemotePlaybackClient.ItemActionCallback)2 SessionActionCallback (android.support.v7.media.RemotePlaybackClient.SessionActionCallback)2 RemovableInRelease (org.chromium.base.annotations.RemovableInRelease)1