android.support.v7.media.MediaControlIntent Java Examples

The following examples show how to use android.support.v7.media.MediaControlIntent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SampleMediaRouteProvider.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
private boolean handleRemove(Intent intent, ControlRequestCallback callback) {
    String sid = intent.getStringExtra(MediaControlIntent.EXTRA_SESSION_ID);
    if (sid == null || !sid.equals(mSessionManager.getSessionId())) {
        return false;
    }

    String iid = intent.getStringExtra(MediaControlIntent.EXTRA_ITEM_ID);
    PlaylistItem item = mSessionManager.remove(iid);
    if (callback != null) {
        if (item != null) {
            Bundle result = new Bundle();
            result.putBundle(MediaControlIntent.EXTRA_ITEM_STATUS,
                    item.getStatus().asBundle());
            callback.onResult(result);
        } else {
            callback.onError("Failed to remove" +
                    ", sid=" + sid + ", iid=" + iid, null);
        }
    }
    return (item != null);
}
 
Example #2
Source File: JukeboxRouteProvider.java    From Popeens-DSub with GNU General Public License v3.0 6 votes vote down vote up
private void broadcastDescriptor() {
	// Create intents
	IntentFilter routeIntentFilter = new IntentFilter();
	routeIntentFilter.addCategory(CATEGORY_JUKEBOX_ROUTE);
	routeIntentFilter.addAction(MediaControlIntent.ACTION_START_SESSION);
	routeIntentFilter.addAction(MediaControlIntent.ACTION_GET_SESSION_STATUS);
	routeIntentFilter.addAction(MediaControlIntent.ACTION_END_SESSION);

	// Create route descriptor
	MediaRouteDescriptor.Builder routeBuilder = new MediaRouteDescriptor.Builder("Jukebox Route", "Subsonic Jukebox");
	routeBuilder.addControlFilter(routeIntentFilter)
			.setPlaybackStream(AudioManager.STREAM_MUSIC)
			.setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)
			.setDescription("Subsonic Jukebox")
			.setVolume(controller == null ? 5 : (int) (controller.getVolume() * 10))
			.setVolumeMax(MAX_VOLUME)
			.setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE);

	// Create descriptor
	MediaRouteProviderDescriptor.Builder providerBuilder = new MediaRouteProviderDescriptor.Builder();
	providerBuilder.addRoute(routeBuilder.build());
	setDescriptor(providerBuilder.build());
}
 
Example #3
Source File: SampleMediaRouteProvider.java    From android-MediaRouter with Apache License 2.0 6 votes vote down vote up
private boolean handleRemove(Intent intent, ControlRequestCallback callback) {
    String sid = intent.getStringExtra(MediaControlIntent.EXTRA_SESSION_ID);
    if (sid == null || !sid.equals(mSessionManager.getSessionId())) {
        return false;
    }

    String iid = intent.getStringExtra(MediaControlIntent.EXTRA_ITEM_ID);
    PlaylistItem item = mSessionManager.remove(iid);
    if (callback != null) {
        if (item != null) {
            Bundle result = new Bundle();
            result.putBundle(MediaControlIntent.EXTRA_ITEM_STATUS,
                    item.getStatus().asBundle());
            callback.onResult(result);
        } else {
            callback.onError("Failed to remove" +
                    ", sid=" + sid + ", iid=" + iid, null);
        }
    }
    return (item != null);
}
 
Example #4
Source File: DefaultMediaRouteController.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Send a start session intent.
 *
 * @param relaunch Whether we should relaunch the cast application.
 * @param resultBundleHandler BundleHandler to handle reply.
 */
private void startSession(boolean relaunch, String sessionId,
        ResultBundleHandler resultBundleHandler) {
    Intent intent = new Intent(MediaControlIntent.ACTION_START_SESSION);
    intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);

    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_STOP_APPLICATION_WHEN_SESSION_ENDS, true);
    intent.putExtra(MediaControlIntent.EXTRA_SESSION_STATUS_UPDATE_RECEIVER,
            mSessionStatusUpdateIntent);
    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_APPLICATION_ID, getCastReceiverId());
    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_RELAUNCH_APPLICATION, relaunch);
    if (sessionId != null) intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sessionId);

    addIntentExtraForDebugLogging(intent);
    sendIntentToRoute(intent, resultBundleHandler);
}
 
Example #5
Source File: SampleMediaRouteProvider.java    From android-MediaRouter with Apache License 2.0 6 votes vote down vote up
private boolean handleGetStatus(Intent intent, ControlRequestCallback callback) {
    String sid = intent.getStringExtra(MediaControlIntent.EXTRA_SESSION_ID);
    String iid = intent.getStringExtra(MediaControlIntent.EXTRA_ITEM_ID);
    Log.d(TAG, mRouteId + ": Received getStatus request, sid=" + sid + ", iid=" + iid);
    PlaylistItem item = mSessionManager.getStatus(iid);
    if (callback != null) {
        if (item != null) {
            Bundle result = new Bundle();
            result.putBundle(MediaControlIntent.EXTRA_ITEM_STATUS,
                    item.getStatus().asBundle());
            callback.onResult(result);
        } else {
            callback.onError("Failed to get status" +
                    ", sid=" + sid + ", iid=" + iid, null);
        }
    }
    return (item != null);
}
 
Example #6
Source File: SampleMediaRouteProvider.java    From android-MediaRouter with Apache License 2.0 6 votes vote down vote up
private boolean handleStartSession(Intent intent, ControlRequestCallback callback) {
    String sid = mSessionManager.startSession();
    Log.d(TAG, "StartSession returns sessionId "+sid);
    if (callback != null) {
        if (sid != null) {
            Bundle result = new Bundle();
            result.putString(MediaControlIntent.EXTRA_SESSION_ID, sid);
            result.putBundle(MediaControlIntent.EXTRA_SESSION_STATUS,
                    mSessionManager.getSessionStatus(sid).asBundle());
            callback.onResult(result);
            mSessionReceiver = (PendingIntent)intent.getParcelableExtra(
                    MediaControlIntent.EXTRA_SESSION_STATUS_UPDATE_RECEIVER);
            handleSessionStatusChange(sid);
        } else {
            callback.onError("Failed to start session.", null);
        }
    }
    return (sid != null);
}
 
Example #7
Source File: SampleMediaRouteProvider.java    From android-MediaRouter with Apache License 2.0 6 votes vote down vote up
private boolean handleGetSessionStatus(Intent intent, ControlRequestCallback callback) {
    String sid = intent.getStringExtra(MediaControlIntent.EXTRA_SESSION_ID);

    MediaSessionStatus sessionStatus = mSessionManager.getSessionStatus(sid);
    if (callback != null) {
        if (sessionStatus != null) {
            Bundle result = new Bundle();
            result.putBundle(MediaControlIntent.EXTRA_SESSION_STATUS,
                    mSessionManager.getSessionStatus(sid).asBundle());
            callback.onResult(result);
        } else {
            callback.onError("Failed to get session status, sid=" + sid, null);
        }
    }
    return (sessionStatus != null);
}
 
Example #8
Source File: SampleMediaRouteProvider.java    From android-MediaRouter with Apache License 2.0 6 votes vote down vote up
private boolean handleEndSession(Intent intent, ControlRequestCallback callback) {
    String sid = intent.getStringExtra(MediaControlIntent.EXTRA_SESSION_ID);
    boolean success = (sid != null) && sid.equals(mSessionManager.getSessionId())
            && mSessionManager.endSession();
    if (callback != null) {
        if (success) {
            Bundle result = new Bundle();
            MediaSessionStatus sessionStatus = new MediaSessionStatus.Builder(
                    MediaSessionStatus.SESSION_STATE_ENDED).build();
            result.putBundle(MediaControlIntent.EXTRA_SESSION_STATUS, sessionStatus.asBundle());
            callback.onResult(result);
            handleSessionStatusChange(sid);
            mSessionReceiver = null;
        } else {
            callback.onError("Failed to end session, sid=" + sid, null);
        }
    }
    return success;
}
 
Example #9
Source File: SampleMediaRouteProvider.java    From android-MediaRouter with Apache License 2.0 6 votes vote down vote up
private void handleStatusChange(PlaylistItem item) {
    if (item == null) {
        item = mSessionManager.getCurrentItem();
    }
    if (item != null) {
        PendingIntent receiver = item.getUpdateReceiver();
        if (receiver != null) {
            Intent intent = new Intent();
            intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, item.getSessionId());
            intent.putExtra(MediaControlIntent.EXTRA_ITEM_ID, item.getItemId());
            intent.putExtra(MediaControlIntent.EXTRA_ITEM_STATUS,
                    item.getStatus().asBundle());
            try {
                receiver.send(getContext(), 0, intent);
                Log.d(TAG, mRouteId + ": Sending status update from provider");
            } catch (PendingIntent.CanceledException e) {
                Log.d(TAG, mRouteId + ": Failed to send status update!");
            }
        }
    }
}
 
Example #10
Source File: SampleMediaRouteProvider.java    From android-MediaRouter with Apache License 2.0 6 votes vote down vote up
private boolean handleSeek(Intent intent, ControlRequestCallback callback) {
    String sid = intent.getStringExtra(MediaControlIntent.EXTRA_SESSION_ID);
    if (sid == null || !sid.equals(mSessionManager.getSessionId())) {
        return false;
    }

    String iid = intent.getStringExtra(MediaControlIntent.EXTRA_ITEM_ID);
    long pos = intent.getLongExtra(MediaControlIntent.EXTRA_ITEM_CONTENT_POSITION, 0);
    Log.d(TAG, mRouteId + ": Received seek request, pos=" + pos);
    PlaylistItem item = mSessionManager.seek(iid, pos);
    if (callback != null) {
        if (item != null) {
            Bundle result = new Bundle();
            result.putBundle(MediaControlIntent.EXTRA_ITEM_STATUS,
                    item.getStatus().asBundle());
            callback.onResult(result);
        } else {
            callback.onError("Failed to seek" +
                    ", sid=" + sid + ", iid=" + iid + ", pos=" + pos, null);
        }
    }
    return (item != null);
}
 
Example #11
Source File: SampleMediaRouteProvider.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
private boolean handleSeek(Intent intent, ControlRequestCallback callback) {
    String sid = intent.getStringExtra(MediaControlIntent.EXTRA_SESSION_ID);
    if (sid == null || !sid.equals(mSessionManager.getSessionId())) {
        return false;
    }

    String iid = intent.getStringExtra(MediaControlIntent.EXTRA_ITEM_ID);
    long pos = intent.getLongExtra(MediaControlIntent.EXTRA_ITEM_CONTENT_POSITION, 0);
    Log.d(TAG, mRouteId + ": Received seek request, pos=" + pos);
    PlaylistItem item = mSessionManager.seek(iid, pos);
    if (callback != null) {
        if (item != null) {
            Bundle result = new Bundle();
            result.putBundle(MediaControlIntent.EXTRA_ITEM_STATUS,
                    item.getStatus().asBundle());
            callback.onResult(result);
        } else {
            callback.onError("Failed to seek" +
                    ", sid=" + sid + ", iid=" + iid + ", pos=" + pos, null);
        }
    }
    return (item != null);
}
 
Example #12
Source File: SampleMediaRouteProvider.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
private boolean handleGetStatus(Intent intent, ControlRequestCallback callback) {
    String sid = intent.getStringExtra(MediaControlIntent.EXTRA_SESSION_ID);
    String iid = intent.getStringExtra(MediaControlIntent.EXTRA_ITEM_ID);
    Log.d(TAG, mRouteId + ": Received getStatus request, sid=" + sid + ", iid=" + iid);
    PlaylistItem item = mSessionManager.getStatus(iid);
    if (callback != null) {
        if (item != null) {
            Bundle result = new Bundle();
            result.putBundle(MediaControlIntent.EXTRA_ITEM_STATUS,
                    item.getStatus().asBundle());
            callback.onResult(result);
        } else {
            callback.onError("Failed to get status" +
                    ", sid=" + sid + ", iid=" + iid, null);
        }
    }
    return (item != null);
}
 
Example #13
Source File: SampleMediaRouteProvider.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
private boolean handleStartSession(Intent intent, ControlRequestCallback callback) {
    String sid = mSessionManager.startSession();
    Log.d(TAG, "StartSession returns sessionId "+sid);
    if (callback != null) {
        if (sid != null) {
            Bundle result = new Bundle();
            result.putString(MediaControlIntent.EXTRA_SESSION_ID, sid);
            result.putBundle(MediaControlIntent.EXTRA_SESSION_STATUS,
                    mSessionManager.getSessionStatus(sid).asBundle());
            callback.onResult(result);
            mSessionReceiver = (PendingIntent)intent.getParcelableExtra(
                    MediaControlIntent.EXTRA_SESSION_STATUS_UPDATE_RECEIVER);
            handleSessionStatusChange(sid);
        } else {
            callback.onError("Failed to start session.", null);
        }
    }
    return (sid != null);
}
 
Example #14
Source File: SampleMediaRouteProvider.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
private boolean handleGetSessionStatus(Intent intent, ControlRequestCallback callback) {
    String sid = intent.getStringExtra(MediaControlIntent.EXTRA_SESSION_ID);

    MediaSessionStatus sessionStatus = mSessionManager.getSessionStatus(sid);
    if (callback != null) {
        if (sessionStatus != null) {
            Bundle result = new Bundle();
            result.putBundle(MediaControlIntent.EXTRA_SESSION_STATUS,
                    mSessionManager.getSessionStatus(sid).asBundle());
            callback.onResult(result);
        } else {
            callback.onError("Failed to get session status, sid=" + sid, null);
        }
    }
    return (sessionStatus != null);
}
 
Example #15
Source File: SampleMediaRouteProvider.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
private boolean handleEndSession(Intent intent, ControlRequestCallback callback) {
    String sid = intent.getStringExtra(MediaControlIntent.EXTRA_SESSION_ID);
    boolean success = (sid != null) && sid.equals(mSessionManager.getSessionId())
            && mSessionManager.endSession();
    if (callback != null) {
        if (success) {
            Bundle result = new Bundle();
            MediaSessionStatus sessionStatus = new MediaSessionStatus.Builder(
                    MediaSessionStatus.SESSION_STATE_ENDED).build();
            result.putBundle(MediaControlIntent.EXTRA_SESSION_STATUS, sessionStatus.asBundle());
            callback.onResult(result);
            handleSessionStatusChange(sid);
            mSessionReceiver = null;
        } else {
            callback.onError("Failed to end session, sid=" + sid, null);
        }
    }
    return success;
}
 
Example #16
Source File: SampleMediaRouteProvider.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
private void handleStatusChange(PlaylistItem item) {
    if (item == null) {
        item = mSessionManager.getCurrentItem();
    }
    if (item != null) {
        PendingIntent receiver = item.getUpdateReceiver();
        if (receiver != null) {
            Intent intent = new Intent();
            intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, item.getSessionId());
            intent.putExtra(MediaControlIntent.EXTRA_ITEM_ID, item.getItemId());
            intent.putExtra(MediaControlIntent.EXTRA_ITEM_STATUS,
                    item.getStatus().asBundle());
            try {
                receiver.send(getContext(), 0, intent);
                Log.d(TAG, mRouteId + ": Sending status update from provider");
            } catch (PendingIntent.CanceledException e) {
                Log.d(TAG, mRouteId + ": Failed to send status update!");
            }
        }
    }
}
 
Example #17
Source File: CastContextImpl.java    From android_packages_apps_GmsCore with Apache License 2.0 6 votes vote down vote up
public CastContextImpl(IObjectWrapper context, CastOptions options, IMediaRouter router, Map<String, IBinder> sessionProviders) throws RemoteException {
    this.context = (Context) ObjectWrapper.unwrap(context);
    this.options = options;
    this.router = router;
    for (Map.Entry<String, IBinder> entry : sessionProviders.entrySet()) {
        this.sessionProviders.put(entry.getKey(), ISessionProvider.Stub.asInterface(entry.getValue()));
    }

    String receiverApplicationId = options.getReceiverApplicationId();
    String defaultCategory = CastMediaControlIntent.categoryForCast(receiverApplicationId);

    this.defaultSessionProvider = this.sessionProviders.get(defaultCategory);

    // TODO: This should incorporate passed options
    this.mergedSelector = new MediaRouteSelector.Builder()
        .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)
        .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
        .addControlCategory(defaultCategory)
        .build();
}
 
Example #18
Source File: DefaultMediaRouteController.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Send a start session intent.
 *
 * @param relaunch Whether we should relaunch the cast application.
 * @param resultBundleHandler BundleHandler to handle reply.
 */
private void startSession(boolean relaunch, String sessionId,
        ResultBundleHandler resultBundleHandler) {
    Intent intent = new Intent(MediaControlIntent.ACTION_START_SESSION);
    intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);

    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_STOP_APPLICATION_WHEN_SESSION_ENDS, true);
    intent.putExtra(MediaControlIntent.EXTRA_SESSION_STATUS_UPDATE_RECEIVER,
            mSessionStatusUpdateIntent);
    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_APPLICATION_ID, getCastReceiverId());
    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_RELAUNCH_APPLICATION, relaunch);
    if (sessionId != null) intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sessionId);

    addIntentExtraForDebugLogging(intent);
    sendIntentToRoute(intent, resultBundleHandler);
}
 
Example #19
Source File: DefaultMediaRouteController.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Send a start session intent.
 *
 * @param relaunch Whether we should relaunch the cast application.
 * @param resultBundleHandler BundleHandler to handle reply.
 */
private void startSession(boolean relaunch, String sessionId,
        ResultBundleHandler resultBundleHandler) {
    Intent intent = new Intent(MediaControlIntent.ACTION_START_SESSION);
    intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);

    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_STOP_APPLICATION_WHEN_SESSION_ENDS, true);
    intent.putExtra(MediaControlIntent.EXTRA_SESSION_STATUS_UPDATE_RECEIVER,
            mSessionStatusUpdateIntent);
    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_APPLICATION_ID, getCastReceiverId());
    intent.putExtra(CastMediaControlIntent.EXTRA_CAST_RELAUNCH_APPLICATION, relaunch);
    if (sessionId != null) intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sessionId);

    addIntentExtraForDebugLogging(intent);
    sendIntentToRoute(intent, resultBundleHandler);
}
 
Example #20
Source File: SampleMediaRouteProvider.java    From android-MediaRouter with Apache License 2.0 5 votes vote down vote up
private void handleSessionStatusChange(String sid) {
    if (mSessionReceiver != null) {
        Intent intent = new Intent();
        intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sid);
        intent.putExtra(MediaControlIntent.EXTRA_SESSION_STATUS,
                mSessionManager.getSessionStatus(sid).asBundle());
        try {
            mSessionReceiver.send(getContext(), 0, intent);
            Log.d(TAG, mRouteId + ": Sending session status update from provider");
        } catch (PendingIntent.CanceledException e) {
            Log.d(TAG, mRouteId + ": Failed to send session status update!");
        }
    }
}
 
Example #21
Source File: DefaultMediaRouteController.java    From delion with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example #22
Source File: Player.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
public static Player create(Context context, RouteInfo route) {
    Player player;
    if (route != null && route.supportsControlCategory(
            MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)) {
        player = new RemotePlayer(context);
    } else if (route != null) {
        player = new LocalPlayer.SurfaceViewPlayer(context);
    } else {
        player = new LocalPlayer.OverlayPlayer(context);
    }
    player.connect(route);
    return player;
}
 
Example #23
Source File: SampleMediaRouteProvider.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
private void handleSessionStatusChange(String sid) {
    if (mSessionReceiver != null) {
        Intent intent = new Intent();
        intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sid);
        intent.putExtra(MediaControlIntent.EXTRA_SESSION_STATUS,
                mSessionManager.getSessionStatus(sid).asBundle());
        try {
            mSessionReceiver.send(getContext(), 0, intent);
            Log.d(TAG, mRouteId + ": Sending session status update from provider");
        } catch (PendingIntent.CanceledException e) {
            Log.d(TAG, mRouteId + ": Failed to send session status update!");
        }
    }
}
 
Example #24
Source File: DefaultMediaRouteController.java    From delion with Apache License 2.0 5 votes vote down vote up
@RemovableInRelease
private void logMediaSessionStatus(Bundle data) {
    MediaSessionStatus status = MediaSessionStatus.fromBundle(
            data.getBundle(MediaControlIntent.EXTRA_SESSION_STATUS));
    int sessionState = status.getSessionState();
    Log.d(TAG, "Session state after ending session: %s", sessionState);
}
 
Example #25
Source File: SampleMediaRouteProvider.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
private boolean handleStop(Intent intent, ControlRequestCallback callback) {
    String sid = intent.getStringExtra(MediaControlIntent.EXTRA_SESSION_ID);
    boolean success = (sid != null) && sid.equals(mSessionManager.getSessionId());
    mSessionManager.stop();
    if (callback != null) {
        if (success) {
            callback.onResult(new Bundle());
            handleSessionStatusChange(sid);
        } else {
            callback.onError("Failed to stop, sid=" + sid, null);
        }
    }
    return success;
}
 
Example #26
Source File: SampleMediaRouteProvider.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
private boolean handleResume(Intent intent, ControlRequestCallback callback) {
    String sid = intent.getStringExtra(MediaControlIntent.EXTRA_SESSION_ID);
    boolean success = (sid != null) && sid.equals(mSessionManager.getSessionId());
    mSessionManager.resume();
    if (callback != null) {
        if (success) {
            callback.onResult(new Bundle());
            handleSessionStatusChange(sid);
        } else {
            callback.onError("Failed to resume, sid=" + sid, null);
        }
    }
    return success;
}
 
Example #27
Source File: SampleMediaRouteProvider.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
private boolean handlePause(Intent intent, ControlRequestCallback callback) {
    String sid = intent.getStringExtra(MediaControlIntent.EXTRA_SESSION_ID);
    boolean success = (sid != null) && sid.equals(mSessionManager.getSessionId());
    mSessionManager.pause();
    if (callback != null) {
        if (success) {
            callback.onResult(new Bundle());
            handleSessionStatusChange(sid);
        } else {
            callback.onError("Failed to pause, sid=" + sid, null);
        }
    }
    return success;
}
 
Example #28
Source File: DefaultMediaRouteController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example #29
Source File: SampleMediaRouteProvider.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
private boolean handlePlay(Intent intent, ControlRequestCallback callback) {
    String sid = intent.getStringExtra(MediaControlIntent.EXTRA_SESSION_ID);
    if (sid != null && !sid.equals(mSessionManager.getSessionId())) {
        Log.d(TAG, "handlePlay fails because of bad sid="+sid);
        return false;
    }
    if (mSessionManager.hasSession()) {
        mSessionManager.stop();
    }
    return handleEnqueue(intent, callback);
}
 
Example #30
Source File: DefaultMediaRouteController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@RemovableInRelease
private void logMediaSessionStatus(Bundle data) {
    MediaSessionStatus status = MediaSessionStatus.fromBundle(
            data.getBundle(MediaControlIntent.EXTRA_SESSION_STATUS));
    int sessionState = status.getSessionState();
    Log.d(TAG, "Session state after ending session: %s", sessionState);
}