本文整理汇总了Java中android.support.v4.media.session.MediaSessionCompat.setPlaybackState方法的典型用法代码示例。如果您正苦于以下问题:Java MediaSessionCompat.setPlaybackState方法的具体用法?Java MediaSessionCompat.setPlaybackState怎么用?Java MediaSessionCompat.setPlaybackState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.media.session.MediaSessionCompat
的用法示例。
在下文中一共展示了MediaSessionCompat.setPlaybackState方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUpRemoteControlClient
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
private void setUpRemoteControlClient() {
final Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.setComponent(mMediaButtonReceiverComponent);
mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
mMediaSession = new MediaSessionCompat(getApplication(), "TAG", mMediaButtonReceiverComponent, null);
mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
PlaybackStateCompat playbackStateCompat = new PlaybackStateCompat.Builder()
.setActions(
PlaybackStateCompat.ACTION_SEEK_TO |
PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS |
PlaybackStateCompat.ACTION_SKIP_TO_NEXT |
PlaybackStateCompat.ACTION_PLAY |
PlaybackStateCompat.ACTION_PAUSE |
PlaybackStateCompat.ACTION_STOP
)
.setState(isPlaying() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED, position(), 1.0f)
.build();
mMediaSession.setPlaybackState(playbackStateCompat);
mMediaSession.setCallback(mMediaSessionCallback);
mMediaSession.setActive(true);
updateRemoteControlClient(META_CHANGED);
mTransportController = mMediaSession.getController().getTransportControls();
}
示例2: initializeMediaSession
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
private void initializeMediaSession() {
mMediaSession = new MediaSessionCompat(getContext(), TAG);
mMediaSession.setFlags(
MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mMediaSession.setMediaButtonReceiver(null);
mStateBuilder = new PlaybackStateCompat.Builder()
.setActions(
PlaybackStateCompat.ACTION_PLAY |
PlaybackStateCompat.ACTION_PAUSE |
PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS |
PlaybackStateCompat.ACTION_PLAY_PAUSE);
mMediaSession.setPlaybackState(mStateBuilder.build());
mMediaSession.setCallback(new MySessionCallback());
mMediaSession.setActive(true);
}
示例3: onCreate
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
@Override
public void onCreate() {
Log.d(TAG, "onCreate");
super.onCreate();
castSessionManager = CastContext.getSharedInstance(this).getSessionManager();
// Create a MediaSessionCompat
mediaSession = new MediaSessionCompat(this, TAG);
// Enable callbacks from MediaButtons and TransportControls
mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
// Set an initial PlaybackState with ACTION_PLAY, so media buttons can start the player
stateBuilder = new PlaybackStateCompat.Builder()
.setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PLAY_PAUSE);
mediaSession.setPlaybackState(stateBuilder.build());
// MySessionCallback() has methods that handle callbacks from a media controller
mediaSession.setCallback(mediaSessionCallback);
// Set the session's token so that client activities can communicate with it.
setSessionToken(mediaSession.getSessionToken());
}
示例4: onCreate
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
// Start a new MediaSession.
mSession = new MediaSessionCompat(this, "MusicService");
mSession.setCallback(mCallback);
mSession.setFlags(
MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
| MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
setSessionToken(mSession.getSessionToken());
// TODO: Uncomment the following line to show a notification.
final MediaNotificationManager mediaNotificationManager =
new MediaNotificationManager(this);
mPlayback =
new PlaybackManager(
this,
new PlaybackManager.Callback() {
@Override
public void onPlaybackStatusChanged(PlaybackStateCompat state) {
mSession.setPlaybackState(state);
// TODO: Uncomment the following line to show a notification.
mediaNotificationManager.update(
mPlayback.getCurrentMedia(), state, getSessionToken());
}
});
}
示例5: initializeMediaSession
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
private void initializeMediaSession() {
// Create a MediaSessionCompat.
mMediaSession = new MediaSessionCompat(getContext(), StepDetailFragment.class.getSimpleName());
// Enable callbacks from MediaButtons and TransportControls.
mMediaSession.setFlags(
MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
// Do not let MediaButtons restart the player when the app is not visible.
mMediaSession.setMediaButtonReceiver(null);
// Set an initial PlaybackState with ACTION_PLAY, so media buttons can start the player.
mStateBuilder = new PlaybackStateCompat.Builder()
.setActions(
PlaybackStateCompat.ACTION_PLAY |
PlaybackStateCompat.ACTION_PAUSE |
PlaybackStateCompat.ACTION_PLAY_PAUSE);
mMediaSession.setPlaybackState(mStateBuilder.build());
// MySessionCallback has methods that handle callbacks from a media controller.
mMediaSession.setCallback(new MediaSessionCallback());
// Start the Media Session since the activity is active.
mMediaSession.setActive(true);
}
示例6: createMediaSession
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
private MediaSessionCompat createMediaSession(Context context) {
// create a media session
MediaSessionCompat session = new MediaSessionCompat(context, LOG_TAG);
session.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
session.setPlaybackState(getPlaybackState());
session.setCallback(new MediaSessionCallback());
if (mStation != null) {
session.setMetadata(getMetadata(context, mStation, null));
}
setSessionToken(session.getSessionToken());
return session;
}
示例7: createMediaSession
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
private void createMediaSession() {
ComponentName receiver = new ComponentName(context.getPackageName(), RemoteReceiver.class.getName());
mediaSession = new MediaSessionCompat(context, "MusicService", receiver, null);
mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mediaSession.setPlaybackState(
new PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_PLAYING, 0, 0)
.setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE)
.build()
);
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.requestAudioFocus(focusChange -> {}, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
mediaSession.setActive(true);
}
示例8: initMediaSession
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
/**
* Initiate a MediaSession to allow the Android system to interact with the player
*/
private void initMediaSession() {
Timber.i("Initializing MediaSession");
ComponentName mbrComponent = new ComponentName(mContext, MediaButtonReceiver.class.getName());
MediaSessionCompat session = new MediaSessionCompat(mContext, TAG, mbrComponent, null);
session.setCallback(new MediaSessionCallback(this));
session.setSessionActivity(
PendingIntent.getActivity(
mContext, 0,
LibraryActivity.newNowPlayingIntent(mContext)
.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
PendingIntent.FLAG_CANCEL_CURRENT));
session.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
| MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
PlaybackStateCompat.Builder state = new PlaybackStateCompat.Builder()
.setActions(PlaybackStateCompat.ACTION_PLAY
| PlaybackStateCompat.ACTION_PLAY_PAUSE
| PlaybackStateCompat.ACTION_SEEK_TO
| PlaybackStateCompat.ACTION_PAUSE
| PlaybackStateCompat.ACTION_SKIP_TO_NEXT
| PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
| PlaybackStateCompat.ACTION_STOP)
.setState(PlaybackStateCompat.STATE_NONE, 0, 0f);
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.setClass(mContext, MediaButtonReceiver.class);
PendingIntent mbrIntent = PendingIntent.getBroadcast(mContext, 0, mediaButtonIntent, 0);
session.setMediaButtonReceiver(mbrIntent);
session.setPlaybackState(state.build());
session.setActive(true);
mMediaSession = session;
}
示例9: createMediaSession
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
private MediaSessionCompat createMediaSession(Context context) {
// create a media session
MediaSessionCompat session = new MediaSessionCompat(context, LOG_TAG);
session.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
session.setPlaybackState(createSessionPlaybackState());
session.setCallback(new MediaSessionCallback());
setSessionToken(session.getSessionToken());
return session;
}
示例10: onCreate
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
// set the initial playback state
playbackState = new PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_NONE, 0, 1.0f)
.build();
// instantiate the media session
mediaSession = new MediaSessionCompat(this, LOG_TAG);
mediaSession.setCallback(mediaSessionCallback);
mediaSession.setActive(true);
mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mediaSession.setPlaybackState(playbackState);
// TODO needs to be tied in to requesting audio focus
//get instance to AudioManager
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
// instantiate and configure the media player
initMusicPlayer();
// instantiate the media controller
try {
mediaController = new MediaControllerCompat(this, mediaSession.getSessionToken());
} catch (RemoteException e) {
e.printStackTrace();
}
}
示例11: setCLient
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
public void setCLient()
{
MediaMetadataRetriever meta = new MediaMetadataRetriever();
Log.d("current song","of client is "+Current_playing_song.gettitle());
try {
meta.setDataSource(getBaseContext(), Current_playing_song.getSonguri());
}
catch (Exception e)
{
e.printStackTrace();
Toast.makeText(getBaseContext(),"Error in playing song",Toast.LENGTH_SHORT).show();
playnext();
}
byte [] b = meta.getEmbeddedPicture();
Bitmap bitmap;
if(b!=null)
{
bitmap = BitmapFactory.decodeByteArray(b,0,b.length);
}
else
{
bitmap = BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher,null) ;
}
ComponentName receiver = new ComponentName(getPackageName(), MediaButtonReceiver.class.getName());
mediaSession = new MediaSessionCompat(this, "MusicService", receiver, null);
mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mediaSession.setPlaybackState(new PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_PLAYING, 0, 0)
.setActions( PlaybackStateCompat.ACTION_SEEK_TO |
PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS |
PlaybackStateCompat.ACTION_SKIP_TO_NEXT |
PlaybackStateCompat.ACTION_PLAY |
PlaybackStateCompat.ACTION_PAUSE |
PlaybackStateCompat.ACTION_STOP)
.build());
mediaSession.setMetadata(new MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST,Current_playing_song.getartist())
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM,Current_playing_song.getalbum())
.putString(MediaMetadataCompat.METADATA_KEY_TITLE,Current_playing_song.gettitle())
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION,Current_playing_song.getDuration())
.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap)
.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bitmap)
.build());
mediaSession.setActive(true);
}
示例12: applyState
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
public static void applyState(MediaSessionCompat session, PlaybackStateCompat playbackState) {
session.setPlaybackState(playbackState);
ensureTransportControls(session, playbackState);
}