本文整理汇总了Java中android.media.session.MediaSession.setActive方法的典型用法代码示例。如果您正苦于以下问题:Java MediaSession.setActive方法的具体用法?Java MediaSession.setActive怎么用?Java MediaSession.setActive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.session.MediaSession
的用法示例。
在下文中一共展示了MediaSession.setActive方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initMediaSession
import android.media.session.MediaSession; //导入方法依赖的package包/类
private void initMediaSession() {
mMediaSession = new MediaSession(mContext, MEDIA_SESSION_TAG);
mMediaSession.setCallback(new MediaSession.Callback() {
@Override
public boolean onMediaButtonEvent(Intent mediaButtonIntent) {
// Consume the media button event here. Should not send it to other apps.
return true;
}
});
mMediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
if (!mMediaSession.isActive()) {
mMediaSession.setActive(true);
}
}
示例2: onCreate
import android.media.session.MediaSession; //导入方法依赖的package包/类
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playback_controls);
loadViews();
setupCallbacks();
mSession = new MediaSession(this, "LeanbackSampleApp");
mSession.setCallback(new MediaSessionCallback());
mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
mSession.setActive(true);
}
示例3: onCreate
import android.media.session.MediaSession; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player);
media = (MediaFile) getIntent().getSerializableExtra(MEDIA);
videoFragment = (VideoFragment) getFragmentManager().findFragmentById(R.id.playback_fragment);
VideoFragmentGlueHost glueHost = new VideoFragmentGlueHost(videoFragment);
subtitleView = (SubtitleView) findViewById(R.id.subtitle_view);
if (subtitleView != null) {
subtitleView.setUserDefaultStyle();
subtitleView.setUserDefaultTextSize();
}
Handler mainHandler = new Handler();
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
MappingTrackSelector trackSelector = new DefaultTrackSelector(mainHandler, videoTrackSelectionFactory);
LoadControl loadControl = new DefaultLoadControl();
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
player.addListener(this);
player.setTextOutput(this);
glueHelper = new ExoPlayerGlue(player, trackSelector, this);
glueHelper.setHost(glueHost);
session = new MediaSession(this, "ITPlayer");
session.setCallback(new ExoPlayerMediaSessionCalback(player));
session.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
session.setActive(true);
MediaMetadata.Builder metaBuilder = new MediaMetadata.Builder();
session.setMetadata(metaBuilder.build());
new SourceTask().execute(media);
}
示例4: onCreate
import android.media.session.MediaSession; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
mPlaybackState = new PlaybackState.Builder()
.setState(PlaybackState.STATE_NONE, 0, 1.0f)
.build();
// 1) set up media session and media session callback
mMediaSession = new MediaSession(this, SESSION_TAG);
mMediaSession.setCallback(mMediaSessionCallback);
mMediaSession.setActive(true);
mMediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
mMediaSession.setPlaybackState(mPlaybackState);
// 2) get instance to AudioManager
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
// 3) create our media player
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnBufferingUpdateListener(this);
// 4) create the media controller
mMediaController = new MediaController(this, mMediaSession.getSessionToken());
}
示例5: register
import android.media.session.MediaSession; //导入方法依赖的package包/类
@Override
public void register(Context context, ComponentName mediaButtonReceiverComponent) {
downloadService = (DownloadService) context;
mediaSession = new MediaSession(downloadService, "DSub MediaSession");
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.setComponent(mediaButtonReceiverComponent);
PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, mediaButtonIntent, 0);
mediaSession.setMediaButtonReceiver(mediaPendingIntent);
Intent activityIntent = new Intent(context, SubsonicFragmentActivity.class);
activityIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true);
activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent activityPendingIntent = PendingIntent.getActivity(context, 0, activityIntent, 0);
mediaSession.setSessionActivity(activityPendingIntent);
mediaSession.setFlags(MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSession.FLAG_HANDLES_MEDIA_BUTTONS);
mediaSession.setCallback(new EventCallback());
AudioAttributes.Builder audioAttributesBuilder = new AudioAttributes.Builder();
audioAttributesBuilder.setUsage(AudioAttributes.USAGE_MEDIA)
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC);
mediaSession.setPlaybackToLocal(audioAttributesBuilder.build());
mediaSession.setActive(true);
Bundle sessionExtras = new Bundle();
sessionExtras.putBoolean(WEAR_BACKGROUND_THEME, true);
sessionExtras.putBoolean(WEAR_RESERVE_SKIP_TO_PREVIOUS, true);
sessionExtras.putBoolean(WEAR_RESERVE_SKIP_TO_NEXT, true);
sessionExtras.putBoolean(AUTO_RESERVE_SKIP_TO_PREVIOUS, true);
sessionExtras.putBoolean(AUTO_RESERVE_SKIP_TO_NEXT, true);
mediaSession.setExtras(sessionExtras);
imageLoader = SubsonicActivity.getStaticImageLoader(context);
}
示例6: initMediaSession
import android.media.session.MediaSession; //导入方法依赖的package包/类
private void initMediaSession() {
mMediaSession = new MediaSession( this, "Android Auto Audio Demo" );
mMediaSession.setActive( true );
mMediaSession.setCallback( mMediaSessionCallback );
mMediaSessionToken = mMediaSession.getSessionToken();
setSessionToken( mMediaSessionToken );
}
示例7: displayNotification
import android.media.session.MediaSession; //导入方法依赖的package包/类
private void displayNotification(Bitmap largeIconBitmap) {
if (Build.VERSION.SDK_INT < 16) {
return;
}
previousNotificationLargeIcon = largeIconBitmap;
NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
if (!radioManager.isPlaying() && cancelNotificationOnStop) {
notificationManager.cancel(1);
} else {
String contentTitle;
String contentText;
String actionTitle;
int actionIcon;
if (radioManager.isPlaying()) {
contentTitle = nowPlaying.get("song");
contentText = currentShow.get("name");
actionTitle = "Stop";
actionIcon = R.drawable.stop;
} else {
contentTitle = "Insanity Radio";
contentText = "103.2FM";
actionTitle = "Play";
actionIcon = R.drawable.play;
}
Intent playPauseIntent = new Intent(getActivity(), PlayPauseReceiver.class);
Intent openAppIntent = new Intent(getActivity(), MainActivity.class);
PendingIntent playPausePendingIntent = PendingIntent.getBroadcast(getActivity(), 0, playPauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent openAppPendingIntent = PendingIntent.getActivity(getActivity(), 0, openAppIntent, 0);
Notification.Builder notificationBuilder = new Notification.Builder(getActivity())
.setSmallIcon(R.drawable.ic_headphone)
.setLargeIcon(largeIconBitmap)
.setContentTitle(contentTitle)
.setContentText(contentText)
.setContentIntent(openAppPendingIntent)
.setOngoing(radioManager.isPlaying());
if (Build.VERSION.SDK_INT >= 17) {
notificationBuilder.setShowWhen(false);
}
if (Build.VERSION.SDK_INT >= 21) {
MediaMetadata.Builder mediaMetadataBuilder = new MediaMetadata.Builder();
mediaMetadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, largeIconBitmap);
MediaSession mediaSession = new MediaSession(getActivity(), "insanityradio");
mediaSession.setActive(true);
mediaSession.setMetadata(mediaMetadataBuilder.build());
notificationBuilder
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setStyle(new Notification.MediaStyle()
.setMediaSession(mediaSession.getSessionToken())
.setShowActionsInCompactView(0))
.setColor(Color.BLACK);
}
if (Build.VERSION.SDK_INT >= 23) {
Notification.Action action = new Notification.Action.Builder(Icon.createWithResource(getActivity(), actionIcon), actionTitle, playPausePendingIntent).build();
notificationBuilder.addAction(action);
} else {
notificationBuilder.addAction(actionIcon, actionTitle, playPausePendingIntent);
}
notificationManager.notify(1, notificationBuilder.build());
}
cancelNotificationOnStop = false;
}
示例8: addAudioButtonClickListener
import android.media.session.MediaSession; //导入方法依赖的package包/类
private void addAudioButtonClickListener() {
try {
audioSession = new MediaSession(getApplicationContext(), "TAG");
audioSession.setCallback(new MediaSession.Callback() {
@Override
public boolean onMediaButtonEvent(final Intent mediaButtonIntent) {
String intentAction = mediaButtonIntent.getAction();
if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
KeyEvent event = mediaButtonIntent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (event != null) {
int action = event.getAction();
if (action == KeyEvent.ACTION_DOWN) {
stopTimeOfGame_millis = event.getDownTime();
double usersReactionTime = (event.getDownTime() - startTimeOfGame_millis) / 1000.0;
UtilsRG.info("event.getDownTime(): " + usersReactionTime);
checkTouchEvent();
}
}
}
//int intentDelta = 50;
//stopTimeOfGame_millis = System.currentTimeMillis() - intentDelta;
//checkTouchEvent();
return super.onMediaButtonEvent(mediaButtonIntent);
}
});
PlaybackState state = new PlaybackState.Builder()
.setActions(PlaybackState.ACTION_PLAY_PAUSE)
.setState(PlaybackState.STATE_PLAYING, 0, 0, 0)
.build();
audioSession.setPlaybackState(state);
audioSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
audioSession.setActive(true);
} catch (Exception e) {
UtilsRG.info("could not addAudioButtonClickListener:" + e.getLocalizedMessage());
}
}
示例9: onCreate
import android.media.session.MediaSession; //导入方法依赖的package包/类
@Override
public void onCreate() {
audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagePlayingProgressDidChanged);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagePlayingPlayStateChanged);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mediaSession = new MediaSession(this, "telegramAudioPlayer");
playbackState = new PlaybackState.Builder();
albumArtPlaceholder = Bitmap.createBitmap(AndroidUtilities.dp(102), AndroidUtilities.dp(102), Bitmap.Config.ARGB_8888);
Drawable placeholder = getResources().getDrawable(R.drawable.nocover_big);
placeholder.setBounds(0, 0, albumArtPlaceholder.getWidth(), albumArtPlaceholder.getHeight());
placeholder.draw(new Canvas(albumArtPlaceholder));
mediaSession.setCallback(new MediaSession.Callback() {
@Override
public void onPlay() {
MediaController.getInstance().playMessage(MediaController.getInstance().getPlayingMessageObject());
}
@Override
public void onPause() {
MediaController.getInstance().pauseMessage(MediaController.getInstance().getPlayingMessageObject());
}
@Override
public void onSkipToNext() {
MediaController.getInstance().playNextMessage();
}
@Override
public void onSkipToPrevious() {
MediaController.getInstance().playPreviousMessage();
}
@Override
public void onStop() {
//stopSelf();
}
});
mediaSession.setActive(true);
}
super.onCreate();
}