Example usage for android.support.v4.media MediaBrowserCompat connect

List of usage examples for android.support.v4.media MediaBrowserCompat connect

Introduction

In this page you can find the example usage for android.support.v4.media MediaBrowserCompat connect.

Prototype

public void connect() 

Source Link

Document

Connects to the media browse service.

Usage

From source file:androidx.media.session.MediaButtonReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (intent == null || !Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())
            || !intent.hasExtra(Intent.EXTRA_KEY_EVENT)) {
        Log.d(TAG, "Ignore unsupported intent: " + intent);
        return;/*  www . j a  v  a2 s. co m*/
    }
    ComponentName mediaButtonServiceComponentName = getServiceComponentByAction(context,
            Intent.ACTION_MEDIA_BUTTON);
    if (mediaButtonServiceComponentName != null) {
        intent.setComponent(mediaButtonServiceComponentName);
        startForegroundService(context, intent);
        return;
    }
    ComponentName mediaBrowserServiceComponentName = getServiceComponentByAction(context,
            MediaBrowserServiceCompat.SERVICE_INTERFACE);
    if (mediaBrowserServiceComponentName != null) {
        PendingResult pendingResult = goAsync();
        Context applicationContext = context.getApplicationContext();
        MediaButtonConnectionCallback connectionCallback = new MediaButtonConnectionCallback(applicationContext,
                intent, pendingResult);
        MediaBrowserCompat mediaBrowser = new MediaBrowserCompat(applicationContext,
                mediaBrowserServiceComponentName, connectionCallback, null);
        connectionCallback.setMediaBrowser(mediaBrowser);
        mediaBrowser.connect();
        return;
    }
    throw new IllegalStateException("Could not find any Service that handles " + Intent.ACTION_MEDIA_BUTTON
            + " or implements a media browser service.");
}

From source file:androidx.media.MediaBrowser2.java

/**
 * Get the library root. Result would be sent back asynchronously with the
 * {@link BrowserCallback#onGetLibraryRootDone(MediaBrowser2, Bundle, String, Bundle)}.
 *
 * @param extras extras for getting root
 * @see BrowserCallback#onGetLibraryRootDone(MediaBrowser2, Bundle, String, Bundle)
 *///from   w  ww.  j  a v a  2s . com
public void getLibraryRoot(@Nullable final Bundle extras) {
    final MediaBrowserCompat browser = getBrowserCompat(extras);
    if (browser != null) {
        // Already connected with the given extras.
        getCallbackExecutor().execute(new Runnable() {
            @Override
            public void run() {
                getCallback().onGetLibraryRootDone(MediaBrowser2.this, extras, browser.getRoot(),
                        browser.getExtras());
            }
        });
    } else {
        MediaBrowserCompat newBrowser = new MediaBrowserCompat(getContext(),
                getSessionToken().getComponentName(), new GetLibraryRootCallback(extras), extras);
        newBrowser.connect();
        synchronized (mLock) {
            mBrowserCompats.put(extras, newBrowser);
        }
    }
}