本文整理匯總了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);
}