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


Java MediaSession.setCallback方法代码示例

本文整理汇总了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);
        }
    }
 
开发者ID:bertrandmartel,项目名称:webradio-tv-app,代码行数:19,代码来源:RadioSingleton.java

示例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 ) ;
}
 
开发者ID:smitzey,项目名称:AndroidAutoTourGuide,代码行数:25,代码来源:MuziKarMusicService.java

示例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());
        }
    });
}
 
开发者ID:googlecodelabs,项目名称:android-music-player,代码行数:22,代码来源:MusicService.java

示例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;
}
 
开发者ID:danrien,项目名称:projectBlue,代码行数:21,代码来源:PlaybackService.java

示例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
    ));
}
 
开发者ID:OpenSilk,项目名称:Orpheus,代码行数:21,代码来源:MediaSessionHelper.java

示例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);
}
 
开发者ID:bassaer,项目名称:HelloTV,代码行数:17,代码来源:PlaybackOverlayActivity.java

示例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);
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:30,代码来源:MusicBrowserService.java

示例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);

}
 
开发者ID:Vinetos,项目名称:Hello-Music-droid,代码行数:12,代码来源:WearBrowserService.java

示例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();
}
 
开发者ID:trevd,项目名称:android_packages_apps_tv,代码行数:14,代码来源:DvrPlaybackMediaSessionHelper.java

示例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);
}
 
开发者ID:irtimmer,项目名称:itplayer,代码行数:39,代码来源:PlayerActivity.java

示例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);
}
 
开发者ID:smitzey,项目名称:AndroidAutoTourGuide,代码行数:11,代码来源:MuziKarMusicService.java

示例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);
}
 
开发者ID:smitzey,项目名称:AndroidAutoTourGuide,代码行数:11,代码来源:MyMusicService.java

示例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);
}
 
开发者ID:Fleker,项目名称:ChannelSurfer,代码行数:11,代码来源:ExoPlayerAudio.java

示例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());
}
 
开发者ID:emuneee,项目名称:MarshmallowFM,代码行数:29,代码来源:AudioPlayerService.java

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


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