當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。