當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaSession.setActive方法代碼示例

本文整理匯總了Java中android.media.session.MediaSession.setActive方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaSession.setActive方法的具體用法?Java MediaSession.setActive怎麽用?Java MediaSession.setActive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.media.session.MediaSession的用法示例。


在下文中一共展示了MediaSession.setActive方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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包/類
/**
 * 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

示例3: 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

示例4: 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

示例5: register

import android.media.session.MediaSession; //導入方法依賴的package包/類
@Override
public void register(Context context, ComponentName mediaButtonReceiverComponent) {
	downloadService = (DownloadService) context;
	mediaSession = new MediaSession(downloadService, "DSub MediaSession");

	Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
	mediaButtonIntent.setComponent(mediaButtonReceiverComponent);
	PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, mediaButtonIntent, 0);
	mediaSession.setMediaButtonReceiver(mediaPendingIntent);

	Intent activityIntent = new Intent(context, SubsonicFragmentActivity.class);
	activityIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true);
	activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	PendingIntent activityPendingIntent = PendingIntent.getActivity(context, 0, activityIntent, 0);
	mediaSession.setSessionActivity(activityPendingIntent);

	mediaSession.setFlags(MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSession.FLAG_HANDLES_MEDIA_BUTTONS);
	mediaSession.setCallback(new EventCallback());

	AudioAttributes.Builder audioAttributesBuilder = new AudioAttributes.Builder();
	audioAttributesBuilder.setUsage(AudioAttributes.USAGE_MEDIA)
		.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC);
	mediaSession.setPlaybackToLocal(audioAttributesBuilder.build());
	mediaSession.setActive(true);

	Bundle sessionExtras = new Bundle();
	sessionExtras.putBoolean(WEAR_BACKGROUND_THEME, true);
	sessionExtras.putBoolean(WEAR_RESERVE_SKIP_TO_PREVIOUS, true);
	sessionExtras.putBoolean(WEAR_RESERVE_SKIP_TO_NEXT, true);
	sessionExtras.putBoolean(AUTO_RESERVE_SKIP_TO_PREVIOUS, true);
	sessionExtras.putBoolean(AUTO_RESERVE_SKIP_TO_NEXT, true);
	mediaSession.setExtras(sessionExtras);

	imageLoader = SubsonicActivity.getStaticImageLoader(context);
}
 
開發者ID:popeen,項目名稱:Popeens-DSub,代碼行數:36,代碼來源:RemoteControlClientLP.java

示例6: initMediaSession

import android.media.session.MediaSession; //導入方法依賴的package包/類
private void initMediaSession() {
    mMediaSession = new MediaSession( this, "Android Auto Audio Demo" );
    mMediaSession.setActive( true );
    mMediaSession.setCallback( mMediaSessionCallback );

    mMediaSessionToken = mMediaSession.getSessionToken();
    setSessionToken( mMediaSessionToken );
}
 
開發者ID:Lakkichand,項目名稱:AndroidDemoProjects,代碼行數:9,代碼來源:AutoMediaBrowserService.java

示例7: displayNotification

import android.media.session.MediaSession; //導入方法依賴的package包/類
private void displayNotification(Bitmap largeIconBitmap) {
    if (Build.VERSION.SDK_INT < 16) {
        return;
    }

    previousNotificationLargeIcon = largeIconBitmap;

    NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);

    if (!radioManager.isPlaying() && cancelNotificationOnStop) {
        notificationManager.cancel(1);
    } else {
        String contentTitle;
        String contentText;
        String actionTitle;

        int actionIcon;

        if (radioManager.isPlaying()) {
            contentTitle = nowPlaying.get("song");
            contentText = currentShow.get("name");
            actionTitle = "Stop";
            actionIcon = R.drawable.stop;
        } else {
            contentTitle = "Insanity Radio";
            contentText = "103.2FM";
            actionTitle = "Play";
            actionIcon = R.drawable.play;
        }

        Intent playPauseIntent = new Intent(getActivity(), PlayPauseReceiver.class);
        Intent openAppIntent = new Intent(getActivity(), MainActivity.class);

        PendingIntent playPausePendingIntent = PendingIntent.getBroadcast(getActivity(), 0, playPauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        PendingIntent openAppPendingIntent = PendingIntent.getActivity(getActivity(), 0, openAppIntent, 0);

        Notification.Builder notificationBuilder = new Notification.Builder(getActivity())
                .setSmallIcon(R.drawable.ic_headphone)
                .setLargeIcon(largeIconBitmap)
                .setContentTitle(contentTitle)
                .setContentText(contentText)
                .setContentIntent(openAppPendingIntent)
                .setOngoing(radioManager.isPlaying());

        if (Build.VERSION.SDK_INT >= 17) {
            notificationBuilder.setShowWhen(false);
        }

        if (Build.VERSION.SDK_INT >= 21) {
            MediaMetadata.Builder mediaMetadataBuilder = new MediaMetadata.Builder();
            mediaMetadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, largeIconBitmap);

            MediaSession mediaSession = new MediaSession(getActivity(), "insanityradio");
            mediaSession.setActive(true);
            mediaSession.setMetadata(mediaMetadataBuilder.build());

            notificationBuilder
                    .setVisibility(Notification.VISIBILITY_PUBLIC)
                    .setStyle(new Notification.MediaStyle()
                            .setMediaSession(mediaSession.getSessionToken())
                            .setShowActionsInCompactView(0))
                    .setColor(Color.BLACK);
        }

        if (Build.VERSION.SDK_INT >= 23) {
            Notification.Action action = new Notification.Action.Builder(Icon.createWithResource(getActivity(), actionIcon), actionTitle, playPausePendingIntent).build();

            notificationBuilder.addAction(action);
        } else {
            notificationBuilder.addAction(actionIcon, actionTitle, playPausePendingIntent);
        }

        notificationManager.notify(1, notificationBuilder.build());
    }

    cancelNotificationOnStop = false;
}
 
開發者ID:dylanmaryk,項目名稱:InsanityRadio-Android,代碼行數:78,代碼來源:FragmentNowPlaying.java

示例8: addAudioButtonClickListener

import android.media.session.MediaSession; //導入方法依賴的package包/類
private void addAudioButtonClickListener() {
    try {
        audioSession = new MediaSession(getApplicationContext(), "TAG");
        audioSession.setCallback(new MediaSession.Callback() {

            @Override
            public boolean onMediaButtonEvent(final Intent mediaButtonIntent) {
                String intentAction = mediaButtonIntent.getAction();
                if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
                    KeyEvent event = mediaButtonIntent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);

                    if (event != null) {
                        int action = event.getAction();
                        if (action == KeyEvent.ACTION_DOWN) {
                            stopTimeOfGame_millis = event.getDownTime();
                            double usersReactionTime = (event.getDownTime() - startTimeOfGame_millis) / 1000.0;
                            UtilsRG.info("event.getDownTime(): " + usersReactionTime);
                            checkTouchEvent();
                        }
                    }
                }
                //int intentDelta = 50;
                //stopTimeOfGame_millis = System.currentTimeMillis() - intentDelta;
                //checkTouchEvent();
                return super.onMediaButtonEvent(mediaButtonIntent);
            }

        });

        PlaybackState state = new PlaybackState.Builder()
                .setActions(PlaybackState.ACTION_PLAY_PAUSE)
                .setState(PlaybackState.STATE_PLAYING, 0, 0, 0)
                .build();
        audioSession.setPlaybackState(state);

        audioSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);

        audioSession.setActive(true);
    } catch (Exception e) {
        UtilsRG.info("could not addAudioButtonClickListener:" + e.getLocalizedMessage());
    }
}
 
開發者ID:lidox,項目名稱:reaction-test,代碼行數:43,代碼來源:GoNoGoGameView.java

示例9: onCreate

import android.media.session.MediaSession; //導入方法依賴的package包/類
@Override
public void onCreate() {
    audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagePlayingProgressDidChanged);
    NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagePlayingPlayStateChanged);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mediaSession = new MediaSession(this, "telegramAudioPlayer");
        playbackState = new PlaybackState.Builder();
        albumArtPlaceholder = Bitmap.createBitmap(AndroidUtilities.dp(102), AndroidUtilities.dp(102), Bitmap.Config.ARGB_8888);
        Drawable placeholder = getResources().getDrawable(R.drawable.nocover_big);
        placeholder.setBounds(0, 0, albumArtPlaceholder.getWidth(), albumArtPlaceholder.getHeight());
        placeholder.draw(new Canvas(albumArtPlaceholder));
        mediaSession.setCallback(new MediaSession.Callback() {
            @Override
            public void onPlay() {
                MediaController.getInstance().playMessage(MediaController.getInstance().getPlayingMessageObject());
            }

            @Override
            public void onPause() {
                MediaController.getInstance().pauseMessage(MediaController.getInstance().getPlayingMessageObject());
            }

            @Override
            public void onSkipToNext() {
                MediaController.getInstance().playNextMessage();
            }

            @Override
            public void onSkipToPrevious() {
                MediaController.getInstance().playPreviousMessage();
            }

            @Override
            public void onStop() {
                //stopSelf();
            }
        });
        mediaSession.setActive(true);
    }

    super.onCreate();
}
 
開發者ID:DrKLO,項目名稱:Telegram,代碼行數:45,代碼來源:MusicPlayerService.java


注:本文中的android.media.session.MediaSession.setActive方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。