Search in sources :

Example 1 with MediaLibrarySessionCallback

use of androidx.media3.session.MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback in project media by androidx.

the class MediaSessionServiceNotificationTest method setUp.

@Before
public void setUp() throws Exception {
    context = ApplicationProvider.getApplicationContext();
    MediaLibrarySessionCallback sessionCallback = new MediaLibrarySessionCallback() {

        @Override
        public MediaSession.ConnectionResult onConnect(MediaSession session, ControllerInfo controller) {
            if (player == null) {
                player = new MockPlayer.Builder().setChangePlayerStateWithTransportControl(true).build();
                session.setPlayer(player);
            }
            if (SUPPORT_APP_PACKAGE_NAME.equals(controller.getPackageName())) {
                return MediaLibrarySessionCallback.super.onConnect(session, controller);
            } else {
                return MediaSession.ConnectionResult.reject();
            }
        }
    };
    TestServiceRegistry.getInstance().setSessionCallback(sessionCallback);
    controllerTestRule.createRemoteController(new SessionToken(context, new ComponentName(context, LocalMockMediaSessionService.class)), /* waitForConnection= */
    true, /* connectionHints= */
    null);
}
Also used : MediaLibrarySessionCallback(androidx.media3.session.MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback) ComponentName(android.content.ComponentName) ControllerInfo(androidx.media3.session.MediaSession.ControllerInfo) Before(org.junit.Before)

Example 2 with MediaLibrarySessionCallback

use of androidx.media3.session.MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback in project media by androidx.

the class MockMediaLibraryService method onGetSession.

@Override
public MediaLibrarySession onGetSession(ControllerInfo controllerInfo) {
    TestServiceRegistry registry = TestServiceRegistry.getInstance();
    TestServiceRegistry.OnGetSessionHandler onGetSessionHandler = registry.getOnGetSessionHandler();
    if (onGetSessionHandler != null) {
        return (MediaLibrarySession) onGetSessionHandler.onGetSession(controllerInfo);
    }
    MockPlayer player = new MockPlayer.Builder().setApplicationLooper(handler.getLooper()).build();
    MediaLibrarySessionCallback callback = registry.getSessionCallback();
    session = new MediaLibrarySession.Builder(MockMediaLibraryService.this, player, callback != null ? callback : new TestLibrarySessionCallback()).setId(ID).build();
    return session;
}
Also used : MediaLibrarySessionCallback(androidx.media3.session.MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback)

Aggregations

MediaLibrarySessionCallback (androidx.media3.session.MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback)2 ComponentName (android.content.ComponentName)1 ControllerInfo (androidx.media3.session.MediaSession.ControllerInfo)1 Before (org.junit.Before)1