use of androidx.media2.session.SessionResult in project ExoPlayer by google.
the class SessionCallbackBuilderTest method assertSessionResultSuccess.
private static void assertSessionResultSuccess(Future<SessionResult> future, long timeoutMs) throws Exception {
SessionResult result = future.get(timeoutMs, MILLISECONDS);
assertThat(result.getResultCode()).isEqualTo(SessionResult.RESULT_SUCCESS);
}
use of androidx.media2.session.SessionResult in project ExoPlayer by google.
the class SessionCallbackBuilderTest method assertSessionResultFailure.
private static void assertSessionResultFailure(Future<SessionResult> future) throws Exception {
SessionResult result = future.get(PLAYER_STATE_CHANGE_OVER_SESSION_WAIT_TIME_MS, MILLISECONDS);
assertThat(result.getResultCode()).isNotEqualTo(SessionResult.RESULT_SUCCESS);
}
use of androidx.media2.session.SessionResult in project ExoPlayer by google.
the class SessionCallbackBuilderTest method setCustomCommandProvider_withCustomCommandProvider_receivesCustomCommand.
@Test
public void setCustomCommandProvider_withCustomCommandProvider_receivesCustomCommand() throws Exception {
SessionCommand testCommand = new SessionCommand("exo.ext.media2.COMMAND", null);
CountDownLatch latch = new CountDownLatch(1);
SessionCallbackBuilder.CustomCommandProvider provider = new SessionCallbackBuilder.CustomCommandProvider() {
@Override
public SessionResult onCustomCommand(MediaSession session, MediaSession.ControllerInfo controllerInfo, SessionCommand customCommand, @Nullable Bundle args) {
assertThat(customCommand.getCustomAction()).isEqualTo(testCommand.getCustomAction());
assertThat(args).isNull();
latch.countDown();
return new SessionResult(SessionResult.RESULT_SUCCESS, null);
}
@Override
public SessionCommandGroup getCustomCommands(MediaSession session, MediaSession.ControllerInfo controllerInfo) {
return new SessionCommandGroup.Builder().addCommand(testCommand).build();
}
};
try (MediaSession session = createMediaSession(sessionPlayerConnector, new SessionCallbackBuilder(context, sessionPlayerConnector).setCustomCommandProvider(provider).build())) {
OnAllowedCommandsChangedListener listener = (controller, allowedCommands) -> {
boolean foundCustomCommand = false;
for (SessionCommand command : allowedCommands.getCommands()) {
if (TextUtils.equals(testCommand.getCustomAction(), command.getCustomAction())) {
foundCustomCommand = true;
break;
}
}
assertThat(foundCustomCommand).isTrue();
};
try (MediaController controller = createConnectedController(session, null, listener)) {
assertSessionResultSuccess(controller.sendCustomCommand(testCommand, null), CONTROLLER_COMMAND_WAIT_TIME_MS);
assertThat(latch.await(0, MILLISECONDS)).isTrue();
}
}
}
Aggregations