android.media.RemoteControlClient Java Examples

The following examples show how to use android.media.RemoteControlClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlaybackService.java    From AntennaPodSP with MIT License 6 votes vote down vote up
@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;
}
 
Example #2
Source File: PlayerService.java    From IdealMedia with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #3
Source File: MusicPlayerService.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@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);
    }
}
 
Example #4
Source File: AvrcpService.java    From Botifier with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
	}
}
 
Example #5
Source File: MusicPlayerService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@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);
    }
}
 
Example #6
Source File: MusicPlayerService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@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);
    }
}
 
Example #7
Source File: ServicePlayer.java    From freemp with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #8
Source File: MediaSessionWrapper.java    From Cheerleader with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example #9
Source File: MainActivity.java    From android-MediaRouter with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #10
Source File: PlaybackService.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example #11
Source File: MusicPlayerService.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@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);
    }
}
 
Example #12
Source File: PlaybackInfo.java    From Noyze with Apache License 2.0 6 votes vote down vote up
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;
    }
}
 
Example #13
Source File: RemoteControlKitKat.java    From Noyze with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source File: MediaProviderDelegate.java    From Noyze with Apache License 2.0 6 votes vote down vote up
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;
    }
}
 
Example #15
Source File: PlaybackInfo.java    From Noyze with Apache License 2.0 6 votes vote down vote up
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;
    }
}
 
Example #16
Source File: d.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #17
Source File: MediaProviderDelegate.java    From Noyze with Apache License 2.0 6 votes vote down vote up
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;
    }
}
 
Example #18
Source File: RemoteControlKitKat.java    From Noyze with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #19
Source File: RemoteControlClientICS.java    From Popeens-DSub with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example #20
Source File: RemoteControlClientICS.java    From Popeens-DSub with GNU General Public License v3.0 6 votes vote down vote up
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);
   	}
}
 
Example #21
Source File: TransportMediatorJellybeanMR2.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void stopPlaying() {
    if (mPlayState != RemoteControlClient.PLAYSTATE_STOPPED) {
        mPlayState = RemoteControlClient.PLAYSTATE_STOPPED;
        mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
    }
    dropAudioFocus();
}
 
Example #22
Source File: TransportMediatorJellybeanMR2.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
void gainFocus() {
    if (!mFocused) {
        mFocused = true;
        mAudioManager.registerMediaButtonEventReceiver(mPendingIntent);
        mAudioManager.registerRemoteControlClient(mRemoteControl);
        if (mPlayState == RemoteControlClient.PLAYSTATE_PLAYING) {
            takeAudioFocus();
        }
    }
}
 
Example #23
Source File: TransportMediatorJellybeanMR2.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
public void refreshState(boolean playing, long position, int transportControls) {
    if (mRemoteControl != null) {
        mRemoteControl.setPlaybackState(playing ? RemoteControlClient.PLAYSTATE_PLAYING
                : RemoteControlClient.PLAYSTATE_STOPPED, position, playing ? 1 : 0);
        mRemoteControl.setTransportControlFlags(transportControls);
    }
}
 
Example #24
Source File: TransportMediatorJellybeanMR2.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
void windowAttached() {
    mContext.registerReceiver(mMediaButtonReceiver, mReceiverFilter);
    mPendingIntent = PendingIntent.getBroadcast(mContext, 0, mIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    mRemoteControl = new RemoteControlClient(mPendingIntent);
    mRemoteControl.setOnGetPlaybackPositionListener(this);
    mRemoteControl.setPlaybackPositionUpdateListener(this);
}
 
Example #25
Source File: TransportMediatorJellybeanMR2.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
void windowAttached() {
    mContext.registerReceiver(mMediaButtonReceiver, mReceiverFilter);
    mPendingIntent = PendingIntent.getBroadcast(mContext, 0, mIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    mRemoteControl = new RemoteControlClient(mPendingIntent);
    mRemoteControl.setOnGetPlaybackPositionListener(this);
    mRemoteControl.setPlaybackPositionUpdateListener(this);
}
 
Example #26
Source File: TransportMediatorJellybeanMR2.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
public void startPlaying() {
    if (mPlayState != RemoteControlClient.PLAYSTATE_PLAYING) {
        mPlayState = RemoteControlClient.PLAYSTATE_PLAYING;
        mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
    }
    if (mFocused) {
        takeAudioFocus();
    }
}
 
Example #27
Source File: PlaybackServiceMediaPlayer.java    From AntennaPodSP with MIT License 5 votes vote down vote up
private void resumeSync() {
    if (playerStatus == PlayerStatus.PAUSED || playerStatus == PlayerStatus.PREPARED) {
        int focusGained = audioManager.requestAudioFocus(
                audioFocusChangeListener, AudioManager.STREAM_MUSIC,
                AudioManager.AUDIOFOCUS_GAIN);
        if (focusGained == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {

            setSpeed(Float.parseFloat(UserPreferences.getPlaybackSpeed()));
            mediaPlayer.start();
            if (playerStatus == PlayerStatus.PREPARED && media.getPosition() > 0) {
                mediaPlayer.seekTo(media.getPosition());
            }

            setPlayerStatus(PlayerStatus.PLAYING, media);
            pausedBecauseOfTransientAudiofocusLoss = false;
            if (android.os.Build.VERSION.SDK_INT >= 14) {
                RemoteControlClient remoteControlClient = callback.getRemoteControlClient();
                if (remoteControlClient != null) {
                    audioManager
                            .registerRemoteControlClient(remoteControlClient);
                }
            }
            audioManager
                    .registerMediaButtonEventReceiver(new ComponentName(context.getPackageName(),
                            MediaButtonReceiver.class.getName()));
            media.onPlaybackStart();

        } else {
            if (AppConfig.DEBUG) Log.e(TAG, "Failed to request audio focus");
        }
    } else {
        if (AppConfig.DEBUG)
            Log.d(TAG, "Call to resume() was ignored because current state of PSMP object is " + playerStatus);
    }
}
 
Example #28
Source File: TransportMediatorJellybeanMR2.java    From guideshow with MIT License 5 votes vote down vote up
public void startPlaying() {
    if (mPlayState != RemoteControlClient.PLAYSTATE_PLAYING) {
        mPlayState = RemoteControlClient.PLAYSTATE_PLAYING;
        mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
    }
    if (mFocused) {
        takeAudioFocus();
    }
}
 
Example #29
Source File: AvrcpService.java    From Botifier with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void resetNotify(boolean close) {
    if (close) {
    	if (mRemoteControlClient != null) {
    		mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
    		mAudioManager.unregisterRemoteControlClient(mRemoteControlClient);
    	}
    	mAudioManager.abandonAudioFocus(mAudioFocusListener);
        mAudioManager.unregisterMediaButtonEventReceiver(mMediaButtonReceiverComponent);
    } else {
        showNotify("Botifier", "Botifier", "Botifier", 0);
    }
}
 
Example #30
Source File: TransportMediatorJellybeanMR2.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
public void stopPlaying() {
    if (mPlayState != RemoteControlClient.PLAYSTATE_STOPPED) {
        mPlayState = RemoteControlClient.PLAYSTATE_STOPPED;
        mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
    }
    dropAudioFocus();
}