类android.media.RemoteControlClient源码实例Demo

下面列出了怎么用android.media.RemoteControlClient的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: TelePlus-Android   文件: MusicPlayerService.java
@SuppressLint("NewApi")
@Override
public void onDestroy() {
    super.onDestroy();
    if (remoteControlClient != null) {
        RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
        metadataEditor.clear();
        metadataEditor.apply();
        audioManager.unregisterRemoteControlClient(remoteControlClient);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mediaSession.release();
    }
    for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
        NotificationCenter.getInstance(a).removeObserver(this, NotificationCenter.messagePlayingDidSeek);
        NotificationCenter.getInstance(a).removeObserver(this, NotificationCenter.messagePlayingPlayStateChanged);
    }
}
 
源代码2 项目: TelePlus-Android   文件: MusicPlayerService.java
@SuppressLint("NewApi")
@Override
public void onDestroy() {
    super.onDestroy();
    if (remoteControlClient != null) {
        RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
        metadataEditor.clear();
        metadataEditor.apply();
        audioManager.unregisterRemoteControlClient(remoteControlClient);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mediaSession.release();
    }
    for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
        NotificationCenter.getInstance(a).removeObserver(this, NotificationCenter.messagePlayingDidSeek);
        NotificationCenter.getInstance(a).removeObserver(this, NotificationCenter.messagePlayingPlayStateChanged);
    }
}
 
源代码3 项目: IdealMedia   文件: PlayerService.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
void registerRemoteControl(ComponentName rcvMedia) {
    mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setComponent(rcvMedia);
    PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(),
            0, mediaButtonIntent, 0);
    remoteControlClient = new RemoteControlClient(mediaPendingIntent);

    remoteControlClient.setTransportControlFlags(
            RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE |
                    RemoteControlClient.FLAG_KEY_MEDIA_NEXT |
                    RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS
    );
    mAudioManager.registerRemoteControlClient(remoteControlClient);
}
 
源代码4 项目: Botifier   文件: AvrcpService.java
public void showNotify(String artist, String album, String title, int tracknr) {
       getAudioFocus();
       mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
	MetadataEditor edit = mRemoteControlClient.editMetadata(true);
	edit.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, title);
	edit.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, artist);
	edit.putString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, artist);
	edit.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, album);
	edit.putLong(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER, tracknr);
       edit.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, 10);
	edit.apply();
	int timeout = getTimeout();
	if (timeout != 0) {
		mHandler.removeMessages(HANDLER_WHAT_CLEAR);
		mHandler.sendEmptyMessageDelayed(HANDLER_WHAT_CLEAR, timeout * 1000);
	}
}
 
源代码5 项目: Cheerleader   文件: MediaSessionWrapper.java
/**
 * Propagate the playback state to the media session and the lock screen remote control.
 * <p/>
 * See also :
 * {@link fr.tvbarthel.cheerleader.library.media.MediaSessionWrapper#PLAYBACK_STATE_STOPPED}
 * {@link fr.tvbarthel.cheerleader.library.media.MediaSessionWrapper#PLAYBACK_STATE_PLAYING}
 * {@link fr.tvbarthel.cheerleader.library.media.MediaSessionWrapper#PLAYBACK_STATE_PAUSED}
 *
 * @param state playback state.
 */
@SuppressWarnings("deprecation")
public void setPlaybackState(int state) {
    switch (state) {
        case PLAYBACK_STATE_STOPPED:
            setRemoteControlClientPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
            setMediaSessionCompatPlaybackState(PlaybackStateCompat.STATE_STOPPED);
            mMediaSession.setActive(false);
            break;
        case PLAYBACK_STATE_PLAYING:
            setRemoteControlClientPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
            setMediaSessionCompatPlaybackState(PlaybackStateCompat.STATE_PLAYING);
            mMediaSession.setActive(true);
            break;
        case PLAYBACK_STATE_PAUSED:
            setRemoteControlClientPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
            setMediaSessionCompatPlaybackState(PlaybackStateCompat.STATE_PAUSED);
            break;
        default:
            Log.e(TAG, "Unknown playback state.");
            break;
    }
}
 
源代码6 项目: VCL-Android   文件: PlaybackService.java
/**
 * A function to control the Remote Control Client. It is needed for
 * compatibility with devices below Ice Cream Sandwich (4.0).
 *
 * @param state Playback state
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setRemoteControlClientPlaybackState(int state) {
    if (!AndroidUtil.isICSOrLater() || mRemoteControlClient == null)
        return;

    switch (state) {
        case MediaPlayer.Event.Playing:
            mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
            break;
        case MediaPlayer.Event.Paused:
            mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
            break;
        case MediaPlayer.Event.Stopped:
            mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
            break;
    }
}
 
源代码7 项目: Telegram   文件: MusicPlayerService.java
@SuppressLint("NewApi")
@Override
public void onDestroy() {
    unregisterReceiver(headsetPlugReceiver);
    super.onDestroy();
    if (remoteControlClient != null) {
        RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
        metadataEditor.clear();
        metadataEditor.apply();
        audioManager.unregisterRemoteControlClient(remoteControlClient);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mediaSession.release();
    }
    for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
        NotificationCenter.getInstance(a).removeObserver(this, NotificationCenter.messagePlayingDidSeek);
        NotificationCenter.getInstance(a).removeObserver(this, NotificationCenter.messagePlayingPlayStateChanged);
        NotificationCenter.getInstance(a).removeObserver(this, NotificationCenter.httpFileDidLoad);
        NotificationCenter.getInstance(a).removeObserver(this, NotificationCenter.fileDidLoad);
    }
}
 
源代码8 项目: Noyze   文件: RemoteControlKitKat.java
/**
 * A map between {@link android.media.RemoteControlClient} flags and {@link android.media.session.PlaybackState} actions.
 * @return The value to provide for {@link android.media.session.PlaybackState} for actions.
 */
private static long getPlaybackStateActions(final int transportControlFlags) {
    final Map<Integer, Long> FLAG_MAP = new HashMap<>();
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_STOP, PlaybackStateCompat.ACTION_STOP);
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_NEXT, PlaybackStateCompat.ACTION_SKIP_TO_NEXT);
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS, PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS);
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_PAUSE, PlaybackStateCompat.ACTION_PAUSE);
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_FAST_FORWARD, PlaybackStateCompat.ACTION_FAST_FORWARD);
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_REWIND, PlaybackStateCompat.ACTION_REWIND);
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_PLAY, PlaybackStateCompat.ACTION_PLAY);
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE, PlaybackStateCompat.ACTION_PLAY_PAUSE);
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_RATING, PlaybackStateCompat.ACTION_SET_RATING);
    long actions = 0;
    for (Map.Entry<Integer, Long> flags : FLAG_MAP.entrySet()) {
        if ((transportControlFlags & flags.getKey()) == flags.getKey()) {
            if (actions == 0)
                actions = flags.getValue();
            else
                actions |= flags.getValue();
        }
    }
    return actions;
}
 
源代码9 项目: Noyze   文件: MediaProviderDelegate.java
static int getStateFromPlayState(PlayState playState) {
    switch (playState) {
        case BUFFERING:
            return RemoteControlClient.PLAYSTATE_BUFFERING;
        case ERROR:
            return RemoteControlClient.PLAYSTATE_ERROR;
        case FAST_FORWARDING:
            return RemoteControlClient.PLAYSTATE_FAST_FORWARDING;
        case PAUSED:
            return RemoteControlClient.PLAYSTATE_PAUSED;
        case PLAYING:
            return RemoteControlClient.PLAYSTATE_PLAYING;
        case REWINDING:
            return RemoteControlClient.PLAYSTATE_REWINDING;
        case SKIPPING_BACKWARDS:
            return RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS;
        case SKIPPING_FORWARDS:
            return RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS;
        case STOPPED:
            return RemoteControlClient.PLAYSTATE_STOPPED;
        default:
            return RemoteControlClient.PLAYSTATE_ERROR;
    }
}
 
源代码10 项目: Noyze   文件: PlaybackInfo.java
public boolean wasPlayingRecently() {
    switch (mState) {
        case RemoteControlClient.PLAYSTATE_PLAYING:
        case RemoteControlClient.PLAYSTATE_FAST_FORWARDING:
        case RemoteControlClient.PLAYSTATE_REWINDING:
        case RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS:
        case RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS:
        case RemoteControlClient.PLAYSTATE_BUFFERING:
            // actively playing or about to play
            return true;
        case RemoteControlClient.PLAYSTATE_STOPPED:
        case RemoteControlClient.PLAYSTATE_PAUSED:
        case RemoteControlClient.PLAYSTATE_ERROR:
            return ((SystemClock.elapsedRealtime() - mStateChangeTimeMs) < DISPLAY_TIMEOUT_MS);
        default:
            LOGE("PlaybackInfo", "Unknown playback state " + mState + " in wasPlayingRecently()");
            return false;
    }
}
 
源代码11 项目: MiBandDecompiled   文件: d.java
public void a(boolean flag, long l1, int i1)
{
    if (m != null)
    {
        RemoteControlClient remotecontrolclient = m;
        byte byte0;
        float f1;
        if (flag)
        {
            byte0 = 3;
        } else
        {
            byte0 = 1;
        }
        if (flag)
        {
            f1 = 1.0F;
        } else
        {
            f1 = 0.0F;
        }
        remotecontrolclient.setPlaybackState(byte0, l1, f1);
        m.setTransportControlFlags(i1);
    }
}
 
源代码12 项目: Popeens-DSub   文件: RemoteControlClientICS.java
public void register(final Context context, final ComponentName mediaButtonReceiverComponent) {
	downloadService = (DownloadService) context;
	AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

	// build the PendingIntent for the remote control client
	Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
	mediaButtonIntent.setComponent(mediaButtonReceiverComponent);
	PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, mediaButtonIntent, 0);

	// create and register the remote control client
	mRemoteControl = new RemoteControlClient(mediaPendingIntent);
	audioManager.registerRemoteControlClient(mRemoteControl);

	mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
	mRemoteControl.setTransportControlFlags(getTransportFlags());
	imageLoader = SubsonicActivity.getStaticImageLoader(context);
}
 
源代码13 项目: Popeens-DSub   文件: RemoteControlClientICS.java
public void updateMetadata(final Context context, final MusicDirectory.Entry currentSong) {
	if(mRemoteControl == null) {
		return;
	}

	if(imageLoader == null) {
		imageLoader = SubsonicActivity.getStaticImageLoader(context);
	}
	
	// Update the remote controls
	RemoteControlClient.MetadataEditor editor = mRemoteControl.editMetadata(true);
	updateMetadata(currentSong, editor);
	editor.apply();
   	if (currentSong == null || imageLoader == null) {
   		updateAlbumArt(currentSong, null);
   	} else {
   		imageLoader.loadImage(context, this, currentSong);
   	}
}
 
源代码14 项目: AntennaPodSP   文件: PlaybackService.java
@SuppressLint("NewApi")
private RemoteControlClient setupRemoteControlClient() {
    if (Build.VERSION.SDK_INT < 14) {
        return null;
    }

    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setComponent(new ComponentName(getPackageName(),
            MediaButtonReceiver.class.getName()));
    PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(
            getApplicationContext(), 0, mediaButtonIntent, 0);
    remoteControlClient = new RemoteControlClient(mediaPendingIntent);
    int controlFlags;
    if (android.os.Build.VERSION.SDK_INT < 16) {
        controlFlags = RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE
                | RemoteControlClient.FLAG_KEY_MEDIA_NEXT;
    } else {
        controlFlags = RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE;
    }
    remoteControlClient.setTransportControlFlags(controlFlags);
    return remoteControlClient;
}
 
源代码15 项目: Noyze   文件: RemoteControlKitKat.java
/**
 * A map between {@link android.media.RemoteControlClient} flags and {@link android.media.session.PlaybackState} actions.
 * @return The value to provide for {@link android.media.session.PlaybackState} for actions.
 */
private static long getPlaybackStateActions(final int transportControlFlags) {
    final Map<Integer, Long> FLAG_MAP = new HashMap<>();
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_STOP, PlaybackStateCompat.ACTION_STOP);
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_NEXT, PlaybackStateCompat.ACTION_SKIP_TO_NEXT);
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS, PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS);
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_PAUSE, PlaybackStateCompat.ACTION_PAUSE);
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_FAST_FORWARD, PlaybackStateCompat.ACTION_FAST_FORWARD);
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_REWIND, PlaybackStateCompat.ACTION_REWIND);
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_PLAY, PlaybackStateCompat.ACTION_PLAY);
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE, PlaybackStateCompat.ACTION_PLAY_PAUSE);
    FLAG_MAP.put(RemoteControlClient.FLAG_KEY_MEDIA_RATING, PlaybackStateCompat.ACTION_SET_RATING);
    long actions = 0;
    for (Map.Entry<Integer, Long> flags : FLAG_MAP.entrySet()) {
        if ((transportControlFlags & flags.getKey()) == flags.getKey()) {
            if (actions == 0)
                actions = flags.getValue();
            else
                actions |= flags.getValue();
        }
    }
    return actions;
}
 
源代码16 项目: Noyze   文件: MediaProviderDelegate.java
static int getStateFromPlayState(PlayState playState) {
    switch (playState) {
        case BUFFERING:
            return RemoteControlClient.PLAYSTATE_BUFFERING;
        case ERROR:
            return RemoteControlClient.PLAYSTATE_ERROR;
        case FAST_FORWARDING:
            return RemoteControlClient.PLAYSTATE_FAST_FORWARDING;
        case PAUSED:
            return RemoteControlClient.PLAYSTATE_PAUSED;
        case PLAYING:
            return RemoteControlClient.PLAYSTATE_PLAYING;
        case REWINDING:
            return RemoteControlClient.PLAYSTATE_REWINDING;
        case SKIPPING_BACKWARDS:
            return RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS;
        case SKIPPING_FORWARDS:
            return RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS;
        case STOPPED:
            return RemoteControlClient.PLAYSTATE_STOPPED;
        default:
            return RemoteControlClient.PLAYSTATE_ERROR;
    }
}
 
源代码17 项目: Noyze   文件: PlaybackInfo.java
public boolean wasPlayingRecently() {
    switch (mState) {
        case RemoteControlClient.PLAYSTATE_PLAYING:
        case RemoteControlClient.PLAYSTATE_FAST_FORWARDING:
        case RemoteControlClient.PLAYSTATE_REWINDING:
        case RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS:
        case RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS:
        case RemoteControlClient.PLAYSTATE_BUFFERING:
            // actively playing or about to play
            return true;
        case RemoteControlClient.PLAYSTATE_STOPPED:
        case RemoteControlClient.PLAYSTATE_PAUSED:
        case RemoteControlClient.PLAYSTATE_ERROR:
            return ((SystemClock.elapsedRealtime() - mStateChangeTimeMs) < DISPLAY_TIMEOUT_MS);
        default:
            LOGE("PlaybackInfo", "Unknown playback state " + mState + " in wasPlayingRecently()");
            return false;
    }
}
 
源代码18 项目: android-MediaRouter   文件: MainActivity.java
private void updateButtons() {
    MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute();
    // show pause or resume icon depending on current state
    mPauseResumeButton.setImageResource(
            mPaused ? R.drawable.ic_action_play : R.drawable.ic_action_pause);
    // disable pause/resume/stop if no session
    mPauseResumeButton.setEnabled(mSessionManager.hasSession());
    mStopButton.setEnabled(mSessionManager.hasSession());
    // only enable seek bar when duration is known
    PlaylistItem item = getCheckedPlaylistItem();
    mSeekBar.setEnabled(item != null && item.getDuration() > 0);
    if (mRemoteControlClient != null) {
        mRemoteControlClient.setPlaybackState(mPaused ? RemoteControlClient.PLAYSTATE_PAUSED :
                RemoteControlClient.PLAYSTATE_PLAYING);
    }
}
 
源代码19 项目: Telegram-FOSS   文件: MusicPlayerService.java
@SuppressLint("NewApi")
@Override
public void onDestroy() {
    unregisterReceiver(headsetPlugReceiver);
    super.onDestroy();
    if (remoteControlClient != null) {
        RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
        metadataEditor.clear();
        metadataEditor.apply();
        audioManager.unregisterRemoteControlClient(remoteControlClient);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mediaSession.release();
    }
    for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
        NotificationCenter.getInstance(a).removeObserver(this, NotificationCenter.messagePlayingDidSeek);
        NotificationCenter.getInstance(a).removeObserver(this, NotificationCenter.messagePlayingPlayStateChanged);
        NotificationCenter.getInstance(a).removeObserver(this, NotificationCenter.httpFileDidLoad);
        NotificationCenter.getInstance(a).removeObserver(this, NotificationCenter.fileDidLoad);
    }
}
 
源代码20 项目: freemp   文件: ServicePlayer.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
void registerRemoteControl(ComponentName rcvMedia) {
    mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN);
    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setComponent(rcvMedia);
    PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(),
            0, mediaButtonIntent, 0);
    remoteControlClient = new RemoteControlClient(mediaPendingIntent);

    remoteControlClient.setTransportControlFlags(
            RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE |
                    RemoteControlClient.FLAG_KEY_MEDIA_NEXT |
                    RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS
    );
    mAudioManager.registerRemoteControlClient(remoteControlClient);
}
 
源代码21 项目: media-samples   文件: MainActivity.java
private void registerRemoteControlClient() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // Create the RCC and register with AudioManager and MediaRouter
        mAudioManager.requestAudioFocus(mAfChangeListener, AudioManager.STREAM_MUSIC,
                AudioManager.AUDIOFOCUS_GAIN);
        mAudioManager.registerMediaButtonEventReceiver(mEventReceiver);
        mRemoteControlClient = new RemoteControlClient(mMediaPendingIntent);
        mAudioManager.registerRemoteControlClient(mRemoteControlClient);
        mMediaRouter.addRemoteControlClient(mRemoteControlClient);
        SampleMediaButtonReceiver.setActivity(MainActivity.this);
        mRemoteControlClient.setTransportControlFlags(RemoteControlClient
                .FLAG_KEY_MEDIA_PLAY_PAUSE);
        mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
    }
}
 
源代码22 项目: guideshow   文件: TransportMediatorJellybeanMR2.java
public void startPlaying() {
    if (mPlayState != RemoteControlClient.PLAYSTATE_PLAYING) {
        mPlayState = RemoteControlClient.PLAYSTATE_PLAYING;
        mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
    }
    if (mFocused) {
        takeAudioFocus();
    }
}
 
源代码23 项目: guideshow   文件: TransportMediatorJellybeanMR2.java
void gainFocus() {
    if (!mFocused) {
        mFocused = true;
        mAudioManager.registerMediaButtonEventReceiver(mPendingIntent);
        mAudioManager.registerRemoteControlClient(mRemoteControl);
        if (mPlayState == RemoteControlClient.PLAYSTATE_PLAYING) {
            takeAudioFocus();
        }
    }
}
 
源代码24 项目: IdealMedia   文件: PlayerService.java
public void pause() {
    BASS.BASS_ChannelPause(stream);
    stopForeground(false);
    stopUpdateProgress();
    saveEqualizerValues();

    // Notify playerInterface
    onUpdatePlayPause();

    // Tell any remote controls that our playback state is 'paused'.
    if (remoteControlClient != null) {
        updateRemoteControlState(RemoteControlClient.PLAYSTATE_PAUSED);
    }
}
 
源代码25 项目: IdealMedia   文件: PlayerService.java
public void stop() {
    BASS.BASS_ChannelStop(stream);
    stopUpdateProgress();
    saveEqualizerValues();

    onUpdatePlayPause();

    if (remoteControlClient != null) {
        updateRemoteControlState(RemoteControlClient.PLAYSTATE_STOPPED);
    }

}
 
源代码26 项目: IdealMedia   文件: PlayerService.java
public void playFromPause() {
    BASS.BASS_ChannelPlay(stream, false);
    startUpdateProgress();

    // Notify playerInterface
    onUpdatePlayPause();

    if (remoteControlClient != null)
        updateRemoteControlState(RemoteControlClient.PLAYSTATE_PLAYING);

    updateWidgets();
    fireNotification();
}
 
源代码27 项目: guideshow   文件: TransportMediatorJellybeanMR2.java
public void stopPlaying() {
    if (mPlayState != RemoteControlClient.PLAYSTATE_STOPPED) {
        mPlayState = RemoteControlClient.PLAYSTATE_STOPPED;
        mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
    }
    dropAudioFocus();
}
 
源代码28 项目: android   文件: VideoCastManager.java
@SuppressLint("InlinedApi")
private void setUpRemoteControl(final MediaInfo info) {
    if (!isFeatureEnabled(BaseCastManager.FEATURE_LOCKSCREEN)) {
        return;
    }
    LOGD(TAG, "setupRemoteControl() was called");
    mAudioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);

    ComponentName eventReceiver = new ComponentName(
            mContext, VideoIntentReceiver.class.getName());
    mAudioManager.registerMediaButtonEventReceiver(eventReceiver);

    if (mRemoteControlClientCompat == null) {
        Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
        intent.setComponent(mMediaButtonReceiverComponent);
        mRemoteControlClientCompat = new RemoteControlClientCompat(
                PendingIntent.getBroadcast(mContext, 0, intent, 0));
        RemoteControlHelper.registerRemoteControlClient(mAudioManager,
                mRemoteControlClientCompat);
    }
    mRemoteControlClientCompat.addToMediaRouter(mMediaRouter);
    mRemoteControlClientCompat.setTransportControlFlags(
            RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE);
    if (null == info) {
        mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
        return;
    } else {
        mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
    }

    // Update the remote control's image
    updateLockScreenImage(info);

    // update the remote control's metadata
    updateLockScreenMetadata();
}
 
源代码29 项目: Cheerleader   文件: MediaSessionWrapper.java
/**
 * Should be called to released the internal component.
 */
@SuppressWarnings("deprecation")
public void onDestroy() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
        mAudioManager.unregisterMediaButtonEventReceiver(mMediaButtonReceiverComponent);
        mLocalBroadcastManager.unregisterReceiver(mLockScreenReceiver);
    }
    mMediaSession.release();
}
 
源代码30 项目: Cheerleader   文件: MediaSessionWrapper.java
/**
 * Update meta data used by the remote control client and the media session.
 *
 * @param track   track currently played.
 * @param artwork track artwork.
 */
@SuppressWarnings("deprecation")
public void setMetaData(SoundCloudTrack track, Bitmap artwork) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {

        // set meta data on the lock screen for pre lollipop.
        mRemoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
        RemoteControlClientCompat.MetadataEditorCompat mediaEditorCompat
                = mRemoteControlClientCompat.editMetadata(true)
                .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, track.getTitle())
                .putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, track.getArtist());
        if (artwork != null) {
            mediaEditorCompat.putBitmap(
                    RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, artwork);
        }
        mediaEditorCompat.apply();
    }

    // set meta data to the media session.
    MediaMetadataCompat.Builder metadataCompatBuilder = new MediaMetadataCompat.Builder()
            .putString(MediaMetadataCompat.METADATA_KEY_TITLE, track.getTitle())
            .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, track.getArtist());
    if (artwork != null) {
        metadataCompatBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, artwork);
    }
    mMediaSession.setMetadata(metadataCompatBuilder.build());
    setMediaSessionCompatPlaybackState(PlaybackStateCompat.STATE_PLAYING);
}
 
 类所在包
 同包方法