当前位置: 首页>>代码示例>>Java>>正文


Java MediaSessionCompat.setMetadata方法代码示例

本文整理汇总了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());
}
 
开发者ID:googlesamples,项目名称:android-PictureInPicture,代码行数:27,代码来源:MediaSessionPlaybackActivity.java

示例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;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:14,代码来源:PlayerService.java

示例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);
}
 
开发者ID:mdnafiskhan,项目名称:Mp3Player,代码行数:48,代码来源:MusicService.java

示例4: setSession

import android.support.v4.media.session.MediaSessionCompat; //导入方法依赖的package包/类
public void setSession(MediaSessionCompat session) {
    if (session != null)
        session.setMetadata(mMetadata);
}
 
开发者ID:lifechurch,项目名称:nuclei-android,代码行数:5,代码来源:MediaMetadata.java

示例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);
}
 
开发者ID:Wojtechnology,项目名称:Sunami,代码行数:49,代码来源:TheBrain.java


注:本文中的android.support.v4.media.session.MediaSessionCompat.setMetadata方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。