本文整理匯總了Java中android.support.v4.media.session.MediaSessionCompat.getMediaSession方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaSessionCompat.getMediaSession方法的具體用法?Java MediaSessionCompat.getMediaSession怎麽用?Java MediaSessionCompat.getMediaSession使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v4.media.session.MediaSessionCompat
的用法示例。
在下文中一共展示了MediaSessionCompat.getMediaSession方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreate
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
LogHelper.d(TAG, "onCreate");
mPlayingQueue = new ArrayList<>();
mMusicProvider = new MusicProvider();
mPackageValidator = new PackageValidator(this);
mEventReceiver = new ComponentName(getPackageName(), MediaButtonReceiver.class.getName());
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.setComponent(mEventReceiver);
mMediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0);
// Start a new MediaSession
mSession = new MediaSessionCompat(this, "MusicService", mEventReceiver, mMediaPendingIntent);
final MediaSessionCallback cb = new MediaSessionCallback();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Shouldn't really have to do this but the MediaSessionCompat method uses
// an internal proxy class, which doesn't forward events such as
// onPlayFromMediaId when running on Lollipop.
final MediaSession session = (MediaSession) mSession.getMediaSession();
session.setCallback(new MediaSessionCallbackProxy(cb));
} else {
mSession.setCallback(cb);
}
setSessionToken(mSession.getSessionToken());
mSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mPlayback = new LocalPlayback(this, mMusicProvider);
mPlayback.setState(PlaybackStateCompat.STATE_NONE);
mPlayback.setCallback(this);
mPlayback.start();
Context context = getApplicationContext();
Intent intent = new Intent(context, NowPlayingActivity.class);
PendingIntent pi = PendingIntent.getActivity(context, 99 /*request code*/,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
mSession.setSessionActivity(pi);
mSessionExtras = new Bundle();
CarHelper.setSlotReservationFlags(mSessionExtras, true, true, true);
mSession.setExtras(mSessionExtras);
updatePlaybackState(null);
mMediaNotificationManager = new MediaNotificationManager(this);
mCastManager = VideoCastManager.getInstance();
mCastManager.addVideoCastConsumer(mCastConsumer);
mMediaRouter = MediaRouter.getInstance(getApplicationContext());
}
示例2: onCreate
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
LogHelper.d(TAG, "onCreate");
mPlayingQueue = new ArrayList<>();
mMusicProvider = new MusicProvider();
mPackageValidator = new PackageValidator(this);
mEventReceiver = new ComponentName(getPackageName(), MediaButtonReceiver.class.getName());
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.setComponent(mEventReceiver);
mMediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0);
// Start a new MediaSession
mSession = new MediaSessionCompat(this, "MusicService", mEventReceiver, mMediaPendingIntent);
final MediaSessionCallback cb = new MediaSessionCallback();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Shouldn't really have to do this but the MediaSessionCompat method uses
// an internal proxy class, which doesn't forward events such as
// onPlayFromMediaId when running on Lollipop.
final MediaSession session = (MediaSession) mSession.getMediaSession();
// session.setCallback(new MediaSessionCallbackProxy(cb));
} else {
mSession.setCallback(cb);
}
setSessionToken(mSession.getSessionToken());
mSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mPlayback = new LocalPlayback(this, mMusicProvider);
mPlayback.setState(PlaybackStateCompat.STATE_NONE);
mPlayback.setCallback(this);
mPlayback.start();
Context context = getApplicationContext();
Intent intent = new Intent(context, NowPlayingActivity.class);
PendingIntent pi = PendingIntent.getActivity(context, 99 /*request code*/,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
mSession.setSessionActivity(pi);
mSessionExtras = new Bundle();
CarHelper.setSlotReservationFlags(mSessionExtras, true, true, true);
mSession.setExtras(mSessionExtras);
updatePlaybackState(null);
mMediaNotificationManager = new MediaNotificationManager(this);
mCastManager = VideoCastManager.getInstance();
mCastManager.addVideoCastConsumer(mCastConsumer);
mMediaRouter = MediaRouter.getInstance(getApplicationContext());
}
示例3: onCreate
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
LogUtils.d(TAG, "onCreate");
mPlayingQueue = new ArrayList<>();
mMusicProvider = new MusicProvider();
mEventReceiver = new ComponentName(getPackageName(), MediaButtonReceiver.class.getName());
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.setComponent(mEventReceiver);
mMediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0);
// Start a new MediaSession
mSession = new MediaSessionCompat(this, "MusicService", mEventReceiver, mMediaPendingIntent);
final MediaSessionCallback cb = new MediaSessionCallback();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Shouldn't really have to do this but the MediaSessionCompat method uses
// an internal proxy class, which doesn't forward events such as
// onPlayFromMediaId when running on Lollipop.
final MediaSession session = (MediaSession) mSession.getMediaSession();
session.setCallback(new MediaSessionCallbackProxy(cb));
} else {
mSession.setCallback(cb);
}
setSessionToken(mSession.getSessionToken());
mSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mPlayback = new LocalPlayback(this, mMusicProvider);
mPlayback.setState(PlaybackStateCompat.STATE_NONE);
mPlayback.setCallback(this);
mPlayback.start();
Context context = getApplicationContext();
Intent intent = new Intent(context, MusicPlayerActivity.class);
PendingIntent pi = PendingIntent.getActivity(context, 99 /*request code*/,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
mSession.setSessionActivity(pi);
mSessionExtras = new Bundle();
mSession.setExtras(mSessionExtras);
updatePlaybackState(null);
mMediaNotificationManager = new MediaNotificationManager(this);
}