本文整理匯總了Java中android.media.session.MediaSession.setCallback方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaSession.setCallback方法的具體用法?Java MediaSession.setCallback怎麽用?Java MediaSession.setCallback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.media.session.MediaSession
的用法示例。
在下文中一共展示了MediaSession.setCallback方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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包/類
@Override
public void onCreate() {
Log.d (TAG, "onCreate() " + this) ;
super.onCreate();
// Start a new MediaSession
mediaSession = new MediaSession(this, "MuziKarMusicService");
mediaSession.setCallback(mediaSessionCallback);
mediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
setSessionToken(mediaSession.getSessionToken());
playbackControlEventBroadcastReceiver = new PlaybackControlEventBroadcastReceiver(this);
audioPlaybackHelper = new AudioPlaybackHelper(getApplicationContext(), new AudioPlaybackHelper.PlayStateChangeCallback() {
@Override
public void onPlaybackStatusChanged(PlaybackState state) {
mediaSession.setPlaybackState(state);
playbackControlEventBroadcastReceiver.update(audioPlaybackHelper.getCurrentMedia(), state, getSessionToken());
}
});
carConnectStatusBroadcastReceiver = new CarConnectStatusBroadcastReceiver( this ) ;
}
示例3: onCreate
import android.media.session.MediaSession; //導入方法依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
// Start a new MediaSession
mSession = new MediaSession(this, "MusicService");
mSession.setCallback(mCallback);
mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
setSessionToken(mSession.getSessionToken());
final MediaNotificationManager mediaNotificationManager = new MediaNotificationManager(this);
mPlayback = new PlaybackManager(this, new PlaybackManager.Callback() {
@Override
public void onPlaybackStatusChanged(PlaybackState state) {
mSession.setPlaybackState(state);
mediaNotificationManager.update(mPlayback.getCurrentMedia(), state, getSessionToken());
}
});
}
示例4: create
import android.media.session.MediaSession; //導入方法依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected MediaSession create() throws Exception {
final MediaSession newMediaSession = new MediaSession(
PlaybackService.this,
mediaSessionTag);
newMediaSession.setFlags(
MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
newMediaSession.setCallback(new MediaSessionCallbackReceiver(PlaybackService.this));
final Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.setComponent(remoteControlReceiver.getObject());
final PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(PlaybackService.this, 0, mediaButtonIntent, 0);
newMediaSession.setMediaButtonReceiver(mediaPendingIntent);
return newMediaSession;
}
示例5: setup
import android.media.session.MediaSession; //導入方法依賴的package包/類
@Override
void setup() {
mHandlerThread = new HandlerThread(getClass().getName(), Process.THREAD_PRIORITY_BACKGROUND);
mHandlerThread.start();
mMediaSession = new MediaSession(mService, mService.getClass().getName());
mMediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS|MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
mMediaSession.setCallback(new Callback(), new Handler(mHandlerThread.getLooper()));
mMediaSession.setMediaButtonReceiver(PendingIntent.getBroadcast(
mService,
1,
new Intent(mService, MediaButtonIntentReceiver.class),
PendingIntent.FLAG_UPDATE_CURRENT
));
mMediaSession.setSessionActivity(PendingIntent.getActivity(
mService,
2,
NavUtils.makeLauncherIntent(mService),
PendingIntent.FLAG_UPDATE_CURRENT
));
}
示例6: 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);
}
示例7: onCreate
import android.media.session.MediaSession; //導入方法依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
ApplicationLoader.postInitApplication();
lastSelectedDialog = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE).getInt("auto_lastSelectedDialog", 0);
mediaSession = new MediaSession(this, "MusicService");
setSessionToken(mediaSession.getSessionToken());
mediaSession.setCallback(new MediaSessionCallback());
mediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
Context context = getApplicationContext();
Intent intent = new Intent(context, LaunchActivity.class);
PendingIntent pi = PendingIntent.getActivity(context, 99, intent, PendingIntent.FLAG_UPDATE_CURRENT);
mediaSession.setSessionActivity(pi);
Bundle extras = new Bundle();
extras.putBoolean(SLOT_RESERVATION_QUEUE, true);
extras.putBoolean(SLOT_RESERVATION_SKIP_TO_PREV, true);
extras.putBoolean(SLOT_RESERVATION_SKIP_TO_NEXT, true);
mediaSession.setExtras(extras);
updatePlaybackState(null);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioPlayStateChanged);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidStarted);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioDidReset);
}
示例8: onCreate
import android.media.session.MediaSession; //導入方法依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
sInstance = this;
mContext = this;
mSession = new MediaSession(this, "WearBrowserService");
setSessionToken(mSession.getSessionToken());
mSession.setCallback(new MediaSessionCallback());
mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
}
示例9: initializeMediaSession
import android.media.session.MediaSession; //導入方法依賴的package包/類
private void initializeMediaSession(String mediaSessionTag) {
mMediaSession = new MediaSession(mActivity, mediaSessionTag);
mMediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS
| MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
mNowPlayingCardWidth = mActivity.getResources()
.getDimensionPixelSize(R.dimen.notif_card_img_max_width);
mNowPlayingCardHeight = mActivity.getResources()
.getDimensionPixelSize(R.dimen.notif_card_img_height);
mMediaSession.setCallback(new MediaSessionCallback());
mActivity.setMediaController(
new MediaController(mActivity, mMediaSession.getSessionToken()));
updateMediaSessionPlaybackState();
}
示例10: 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);
}
示例11: onCreate
import android.media.session.MediaSession; //導入方法依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
mediaSession = new MediaSession(this, "MuziKarMusicService");
setSessionToken(mediaSession.getSessionToken());
mediaSession.setCallback(new MediaSessionCallback());
mediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
}
示例12: onCreate
import android.media.session.MediaSession; //導入方法依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
mSession = new MediaSession(this, "MyMusicService");
setSessionToken(mSession.getSessionToken());
mSession.setCallback(new MediaSessionCallback());
mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
}
示例13: onCreate
import android.media.session.MediaSession; //導入方法依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
mSession = new MediaSession(this, "ExoPlayerAudio");
setSessionToken(mSession.getSessionToken());
mSession.setCallback(new MediaSessionCallback());
mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
}
示例14: 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());
}
示例15: onCreate
import android.media.session.MediaSession; //導入方法依賴的package包/類
@Override
public void onCreate() {
super.onCreate();
LogHelper.d(TAG, "onCreate");
mPlayingQueue = new ArrayList<>();
mMusicProvider = new MusicProvider();
mPackageValidator = new PackageValidator(this);
// Start a new MediaSession
mSession = new MediaSession(this, "MusicService");
setSessionToken(mSession.getSessionToken());
mSession.setCallback(new MediaSessionCallback());
mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
mPlayback = new LocalPlayback(this, mMusicProvider);
mPlayback.setState(PlaybackState.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 = ((UAMPApplication)getApplication()).getCastManager(getApplicationContext());
mCastManager.addVideoCastConsumer(mCastConsumer);
mMediaRouter = MediaRouter.getInstance(getApplicationContext());
}