当前位置: 首页>>代码示例>>Java>>正文


Java MediaSession.Token方法代码示例

本文整理汇总了Java中android.media.session.MediaSession.Token方法的典型用法代码示例。如果您正苦于以下问题:Java MediaSession.Token方法的具体用法?Java MediaSession.Token怎么用?Java MediaSession.Token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.session.MediaSession的用法示例。


在下文中一共展示了MediaSession.Token方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: connectToSession

import android.media.session.MediaSession; //导入方法依赖的package包/类
private void connectToSession(MediaSession.Token token) {
    MediaController mediaController = new MediaController(this, token);
    setMediaController(mediaController);
    mediaController.registerCallback(mMediaControllerCallback);

    if (shouldShowControls()) {
        showPlaybackControls();
    } else {
        LogHelper.d(TAG, "connectionCallback.onConnected: " +
            "hiding controls because metadata is null");
        hidePlaybackControls();
    }

    if (mControlsFragment != null) {
        mControlsFragment.onConnected();
    }

    onMediaControllerConnected();
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:20,代码来源:BaseActivity.java

示例2: connectToSession

import android.media.session.MediaSession; //导入方法依赖的package包/类
private void connectToSession(MediaSession.Token token) {
    MediaController mediaController = new MediaController(FullScreenPlayerActivity.this, token);
    if (mediaController.getMetadata() == null) {
        finish();
        return;
    }
    setMediaController(mediaController);
    mediaController.registerCallback(mCallback);
    PlaybackState state = mediaController.getPlaybackState();
    updatePlaybackState(state);
    MediaMetadata metadata = mediaController.getMetadata();
    if (metadata != null) {
        updateMediaDescription(metadata.getDescription());
        updateDuration(metadata);
    }
    updateProgress();
    if (state != null && (state.getState() == PlaybackState.STATE_PLAYING ||
            state.getState() == PlaybackState.STATE_BUFFERING)) {
        scheduleSeekbarUpdate();
    }
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:22,代码来源:FullScreenPlayerActivity.java

示例3: fromSessionToken

import android.media.session.MediaSession; //导入方法依赖的package包/类
public static MediaAppEntry fromSessionToken(MediaSession.Token sessionToken,
                                             String appName,
                                             String packageName,
                                             Drawable appIcon) {
    return new MediaAppEntry(appName, packageName, appIcon) {
        @Override
        public void getSessionToken(Context context, SessionTokenAvailableCallback callback) {
            callback.onSuccess(MediaSessionCompat.Token.fromToken(sessionToken));
        }
    };
}
 
开发者ID:googlesamples,项目名称:android-media-controller,代码行数:12,代码来源:MediaAppEntry.java

示例4: onConnected

import android.media.session.MediaSession; //导入方法依赖的package包/类
@Override
public void onConnected() {
    LogHelper.d(TAG, "onConnected");

    MediaSession.Token token = mMediaBrowser.getSessionToken();
    if (token == null) {
        throw new IllegalArgumentException("No Session token");
    }
    connectToSession(token);
}
 
开发者ID:ErNaveen,项目名称:UniversalMusicPlayer,代码行数:11,代码来源:BaseActivity.java

示例5: unregister

import android.media.session.MediaSession; //导入方法依赖的package包/类
private void unregister() {
    for (Map.Entry<MediaSession.Token, Pair<MediaController, MediaController.Callback>> entry : mControllers.entrySet()) {
        Pair<MediaController, MediaController.Callback> pair = entry.getValue();
        pair.first.unregisterCallback(pair.second);
    }
    synchronized (mControllers) {
        mControllers.clear();
    }
}
 
开发者ID:Tombarr,项目名称:Noyze,代码行数:10,代码来源:RemoteControlLollipop.java

示例6: buildNotification

import android.media.session.MediaSession; //导入方法依赖的package包/类
/**
 * Call this to build the {@link Notification}.
 */
public void buildNotification(final String albumName, final String artistName,
        final String trackName, final Bitmap albumArt,
        final boolean isPlaying, MediaSession.Token mediaToken) {

    {
        // Default notfication layout
        mNotificationTemplate = new RemoteViews(mService.getPackageName(),
                R.layout.notification_template_base);

        // Set up the content view
        initCollapsedLayout(trackName, artistName, albumArt);

        // Notification Builder
        mNotification = new NotificationCompat.Builder(mService)
                .setSmallIcon(R.drawable.stat_notify_music)
                .setContentIntent(getPendingIntent())
                .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setCategory(NotificationCompat.CATEGORY_TRANSPORT)
                .setContent(mNotificationTemplate)
                .build();
        // Control playback from the notification
        initPlaybackActions(isPlaying);
        if (VersionUtils.hasJellyBean()) {
            // Expanded notifiction style
            mExpandedView = new RemoteViews(mService.getPackageName(),
                    R.layout.notification_template_expanded_base);
            mNotification.bigContentView = mExpandedView;
            // Control playback from the notification
            initExpandedPlaybackActions(isPlaying);
            // Set up the expanded content view
            initExpandedLayout(trackName, albumName, artistName, albumArt);
        }
    }

    mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
    mService.startForeground(APOLLO_MUSIC_SERVICE, mNotification);
}
 
开发者ID:OpenSilk,项目名称:Orpheus,代码行数:42,代码来源:NotificationHelper.java

示例7: update

import android.media.session.MediaSession; //导入方法依赖的package包/类
public void update(MediaMetadata metadata, PlaybackState state, MediaSession.Token token) {
    if (state == null || state.getState() == PlaybackState.STATE_STOPPED ||
            state.getState() == PlaybackState.STATE_NONE) {
        muziKarMusicService.stopForeground(true);
        try {
            muziKarMusicService.unregisterReceiver(this);
        } catch (IllegalArgumentException ex) {
            Log.w ( TAG, "update metadata=" + metadata) ;
        }
        muziKarMusicService.stopSelf();
        return;
    }
    if (metadata == null) {
        return;
    }
    boolean isPlaying = state.getState() == PlaybackState.STATE_PLAYING;
    Notification.Builder notificationBuilder = new Notification.Builder(muziKarMusicService);
    MediaDescription description = metadata.getDescription();

    notificationBuilder
            .setContentTitle(description.getTitle())
            .setVisibility(Notification.VISIBILITY_PUBLIC)
            .setOngoing(isPlaying)
            .setWhen(isPlaying ? System.currentTimeMillis() - state.getPosition() : 0)
            .setShowWhen(isPlaying)
            .setUsesChronometer(isPlaying)
            .setContentText(description.getSubtitle())
            .setLargeIcon(LocalMusicSource.getAlbumBitmap(muziKarMusicService, description.getMediaId()))
            .setStyle(new Notification.MediaStyle().setMediaSession(token).setShowActionsInCompactView(0, 1, 2))
            .setColor(muziKarMusicService.getApplication().getResources().getColor(R.color.colorPrimary))
            .setSmallIcon(R.drawable.art);

    if ((state.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(previousAction);
    }

    notificationBuilder.addAction(isPlaying ? pauseAction : playAction);
    if ((state.getActions() & PlaybackState.ACTION_SKIP_TO_NEXT) != 0) {
        notificationBuilder.addAction(nextAction);
    }

    Notification notification = notificationBuilder.build();

    if (isPlaying && !runningFlag) {
        muziKarMusicService.startService(new Intent(muziKarMusicService.getApplicationContext(), MuziKarMusicService.class));
        muziKarMusicService.startForeground(NOTIFICATION_ID, notification);
        runningFlag = true;
    } else {
        if (!isPlaying) {
            muziKarMusicService.stopForeground(false);
            runningFlag = false;
        }
        notificationManager.notify(NOTIFICATION_ID, notification);
    }
}
 
开发者ID:smitzey,项目名称:AndroidAutoTourGuide,代码行数:56,代码来源:PlaybackControlEventBroadcastReceiver.java

示例8: update

import android.media.session.MediaSession; //导入方法依赖的package包/类
public void update(MediaMetadata metadata, PlaybackState state, MediaSession.Token token) {
    if (state == null || state.getState() == PlaybackState.STATE_STOPPED ||
            state.getState() == PlaybackState.STATE_NONE) {
        mService.stopForeground(true);
        try {
            mService.unregisterReceiver(this);
        } catch (IllegalArgumentException ex) {
            // ignore receiver not registered
        }
        mService.stopSelf();
        return;
    }
    if (metadata == null) {
        return;
    }
    boolean isPlaying = state.getState() == PlaybackState.STATE_PLAYING;
    Notification.Builder notificationBuilder = new Notification.Builder(mService);
    MediaDescription description = metadata.getDescription();

    notificationBuilder
            .setStyle(new Notification.MediaStyle()
                    .setMediaSession(token)
                    .setShowActionsInCompactView(0, 1, 2))
            .setColor(mService.getApplication().getResources().getColor(R.color.notification_bg))
            .setSmallIcon(R.drawable.ic_notification)
            .setVisibility(Notification.VISIBILITY_PUBLIC)
            .setContentIntent(createContentIntent())
            .setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle())
            .setLargeIcon(MusicLibrary.getAlbumBitmap(mService, description.getMediaId()))
            .setOngoing(isPlaying)
            .setWhen(isPlaying ? System.currentTimeMillis() - state.getPosition() : 0)
            .setShowWhen(isPlaying)
            .setUsesChronometer(isPlaying);

    // If skip to next action is enabled
    if ((state.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(mPrevAction);
    }

    notificationBuilder.addAction(isPlaying ? mPauseAction : mPlayAction);

    // If skip to prev action is enabled
    if ((state.getActions() & PlaybackState.ACTION_SKIP_TO_NEXT) != 0) {
        notificationBuilder.addAction(mNextAction);
    }

    Notification notification = notificationBuilder.build();

    if (isPlaying && !mStarted) {
        mService.startService(new Intent(mService.getApplicationContext(), MusicService.class));
        mService.startForeground(NOTIFICATION_ID, notification);
        mStarted = true;
    } else {
        if (!isPlaying) {
            mService.stopForeground(false);
            mStarted = false;
        }
        mNotificationManager.notify(NOTIFICATION_ID, notification);
    }
}
 
开发者ID:googlecodelabs,项目名称:android-music-player,代码行数:62,代码来源:MediaNotificationManager.java

示例9: getMediaSessionToken

import android.media.session.MediaSession; //导入方法依赖的package包/类
public MediaSession.Token getMediaSessionToken() {
    return mMediaSession.getSessionToken();
}
 
开发者ID:emuneee,项目名称:MarshmallowFM,代码行数:4,代码来源:AudioPlayerService.java

示例10: fromToken

import android.media.session.MediaSession; //导入方法依赖的package包/类
public static Object fromToken(Context context, Object sessionToken) {
    return new MediaController(context, (MediaSession.Token) sessionToken);
}
 
开发者ID:kingargyle,项目名称:adt-leanback-support,代码行数:4,代码来源:MediaControllerCompatApi21.java

示例11: EventUpdateMetadata

import android.media.session.MediaSession; //导入方法依赖的package包/类
public EventUpdateMetadata(@NonNull MediaSession.Token token) {
    super();
    mHandler = new Handler(Looper.getMainLooper());
    mToken = token;
}
 
开发者ID:AChep,项目名称:AcDisplay,代码行数:6,代码来源:MediaController2Lollipop.java

示例12: getSessionToken

import android.media.session.MediaSession; //导入方法依赖的package包/类
public MediaSession.Token getSessionToken() {
    return IMPL.getMediaToken();
}
 
开发者ID:OpenSilk,项目名称:Orpheus,代码行数:4,代码来源:MediaSessionHelper.java

示例13: getMediaToken

import android.media.session.MediaSession; //导入方法依赖的package包/类
MediaSession.Token getMediaToken() {
    return null;
}
 
开发者ID:OpenSilk,项目名称:Orpheus,代码行数:4,代码来源:MediaSessionHelper.java

示例14: setSessionToken

import android.media.session.MediaSession; //导入方法依赖的package包/类
@Override
public void setSessionToken(Object token) {
    super.setSessionToken((MediaSession.Token) token);
}
 
开发者ID:OpenSilk,项目名称:Orpheus,代码行数:5,代码来源:PlaybackServiceL.java

示例15: getSessionToken

import android.media.session.MediaSession; //导入方法依赖的package包/类
public MediaSession.Token getSessionToken() {
    return mSession.getSessionToken();
}
 
开发者ID:OpenSilk,项目名称:Orpheus,代码行数:4,代码来源:MediaSessionHolderL.java


注:本文中的android.media.session.MediaSession.Token方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。