Java Code Examples for android.media.session.MediaController#getMetadata()

The following examples show how to use android.media.session.MediaController#getMetadata() . 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: MediaController2Lollipop.java    From AcDisplay with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run(@NonNull MediaController2 mc) {
    final MediaController2Lollipop mcl = (MediaController2Lollipop) mc;
    final MediaController source = mcl.mMediaController;

    if (source != null && mToken.equals(source.getSessionToken())) {
        long now = SystemClock.elapsedRealtime();

        final MediaMetadata metadata = source.getMetadata();
        final PlaybackState playbackState = source.getPlaybackState();

        long delta = SystemClock.elapsedRealtime() - now;
        Log.i(TAG, "Got the new metadata & playback state in " + delta + " millis. "
                + "The media controller is " + source.getPackageName());

        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mcl.updateMetadata(metadata);
                mcl.updatePlaybackState(playbackState);
            }
        });
    }
}
 
Example 2
Source File: MainActivity.java    From PodEmu with GNU General Public License v3.0 4 votes vote down vote up
private void updateAppInfo()
{
    PackageManager pm = getPackageManager();
    ApplicationInfo appInfo;
    String appName = "unknown";
    MediaController mediaController = MediaPlayback.getActiveMediaController();
    Bitmap trackIcon = null;

    if(mediaController != null && mediaController.getMetadata()!=null)
    {
        trackIcon = mediaController.getMetadata().getBitmap(MediaMetadata.METADATA_KEY_ART);
        if (trackIcon == null)
            trackIcon = mediaController.getMetadata().getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART);
        if (trackIcon == null)
            trackIcon = mediaController.getMetadata().getBitmap(MediaMetadata.METADATA_KEY_DISPLAY_ICON);
    }
    else
    {
        PodEmuLog.debug("MA: cannot load icon because mediaController is not initialized");
    }

    if(currentlyPlaying==null) return;
    appName = currentlyPlaying.getApplication();

    PodEmuLog.debug("MA: setting AppInfo to " + appName);


    try
    {
        appInfo = pm.getApplicationInfo(appName, PackageManager.GET_META_DATA);
        ctrlAppStatusTitle.setText("App: " + appInfo.loadLabel(pm));
        ctrlAppStatusTitle.setTextColor(Color.rgb(0xff, 0xff, 0xff));

        if(trackIcon != null)
            setAppLogo(new BitmapDrawable(getResources(), trackIcon) );
        else
            setAppLogo(appInfo.loadIcon(pm));

    }
    catch (PackageManager.NameNotFoundException e)
    {
        ctrlAppStatusTitle.setText("Unknown app");
        ctrlAppStatusTitle.setTextColor(Color.rgb(0xff, 0x00, 0x00));

        setAppLogo(getDrawable(R.drawable.questionmark));
    }

}