本文整理汇总了Java中android.support.v4.media.session.MediaSessionCompat.setMetadata方法的典型用法代码示例。如果您正苦于以下问题:Java MediaSessionCompat.setMetadata方法的具体用法?Java MediaSessionCompat.setMetadata怎么用?Java MediaSessionCompat.setMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.media.session.MediaSessionCompat
的用法示例。
在下文中一共展示了MediaSessionCompat.setMetadata方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeMediaSession
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
private void initializeMediaSession() {
mSession = new MediaSessionCompat(this, TAG);
mSession.setFlags(
MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS
| MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mSession.setActive(true);
MediaControllerCompat.setMediaController(this, mSession.getController());
MediaMetadataCompat metadata = new MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, mMovieView.getTitle())
.build();
mSession.setMetadata(metadata);
MediaSessionCallback mMediaSessionCallback = new MediaSessionCallback(mMovieView);
mSession.setCallback(mMediaSessionCallback);
int state =
mMovieView.isPlaying()
? PlaybackStateCompat.STATE_PLAYING
: PlaybackStateCompat.STATE_PAUSED;
updatePlaybackState(
state,
MEDIA_ACTIONS_ALL,
mMovieView.getCurrentPosition(),
mMovieView.getVideoResourceId());
}
示例2: 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;
}
示例3: 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);
}
示例4: setSession
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
public void setSession(MediaSessionCompat session) {
if (session != null)
session.setMetadata(mMetadata);
}
示例5: registerAudio
import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
private void registerAudio() {
if (mHasAudioFocus || !mIsInit) {
return;
}
mHasAudioFocus = true;
// Add audio focus change listener
mAFChangeListener = new AudioManager.OnAudioFocusChangeListener() {
public void onAudioFocusChange(int focusChange) {
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
pausePlayback();
setUI(false);
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
// Does nothing cause made me play music at work
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
pausePlayback();
unregisterAudio();
setUI(false);
}
}
};
mAudioManager.requestAudioFocus(mAFChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
// Add headphone out listener
registerReceiver(mNoisyAudioStreamReceiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
// Add notification and transport controls
ComponentName eventReceiver = new ComponentName(getPackageName(), RemoteControlEventReceiver.class.getName());
mSession = new MediaSessionCompat(this, "FireSession", eventReceiver, null);
mSession.setFlags(MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS);
mSession.setPlaybackToLocal(AudioManager.STREAM_MUSIC);
mSession.setMetadata(new MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, "")
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, "")
.putLong(MediaMetadata.METADATA_KEY_DURATION, -1)
.build());
mSession.setCallback(new MediaSessionCompat.Callback() {
@Override
public void onSeekTo(long pos) {
super.onSeekTo(pos);
setProgress((int) pos, isPlaying());
}
});
mSession.setActive(true);
}