Search in sources :

Example 1 with RemoteControlClient

use of android.media.RemoteControlClient in project frostwire by frostwire.

the class MusicPlaybackService method setUpRemoteControlClient.

/**
 * Initializes the remote control client
 */
private void setUpRemoteControlClient() {
    final Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setComponent(mMediaButtonReceiverComponent);
    mRemoteControlClient = new RemoteControlClient(PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT));
    try {
        if (mAudioManager != null) {
            mAudioManager.registerRemoteControlClient(mRemoteControlClient);
        }
    } catch (Throwable t) {
    // seems like this doesn't work on some devices where it requires MODIFY_PHONE_STATE
    // which is a permission only given to system apps, not third party apps.
    }
    // Flags for the media transport control that this client supports.
    int flags = RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP;
    flags |= RemoteControlClient.FLAG_KEY_MEDIA_POSITION_UPDATE;
    mRemoteControlClient.setOnGetPlaybackPositionListener(this::position);
    mRemoteControlClient.setPlaybackPositionUpdateListener(this::seek);
    mRemoteControlClient.setTransportControlFlags(flags);
}
Also used : RemoteControlClient(android.media.RemoteControlClient) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 2 with RemoteControlClient

use of android.media.RemoteControlClient in project ultrasonic by ultrasonic.

the class DownloadServiceImpl method setUpRemoteControlClient.

@SuppressLint("NewApi")
public void setUpRemoteControlClient() {
    if (!Util.isLockScreenEnabled(this))
        return;
    ComponentName componentName = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName());
    if (remoteControlClient == null) {
        final Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
        mediaButtonIntent.setComponent(componentName);
        PendingIntent broadcast = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        remoteControlClient = new RemoteControlClient(broadcast);
        audioManager.registerRemoteControlClient(remoteControlClient);
        // Flags for the media transport control that this client supports.
        int flags = RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_STOP;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            flags |= RemoteControlClient.FLAG_KEY_MEDIA_POSITION_UPDATE;
            remoteControlClient.setOnGetPlaybackPositionListener(new RemoteControlClient.OnGetPlaybackPositionListener() {

                @Override
                public long onGetPlaybackPosition() {
                    return mediaPlayer.getCurrentPosition();
                }
            });
            remoteControlClient.setPlaybackPositionUpdateListener(new RemoteControlClient.OnPlaybackPositionUpdateListener() {

                @Override
                public void onPlaybackPositionUpdate(long newPositionMs) {
                    seekTo((int) newPositionMs);
                }
            });
        }
        remoteControlClient.setTransportControlFlags(flags);
    }
}
Also used : MediaButtonIntentReceiver(org.moire.ultrasonic.receiver.MediaButtonIntentReceiver) RemoteControlClient(android.media.RemoteControlClient) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 3 with RemoteControlClient

use of android.media.RemoteControlClient in project CodenameOne by codenameone.

the class TransportMediatorJellybeanMR2 method windowAttached.

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);
}
Also used : RemoteControlClient(android.media.RemoteControlClient)

Example 4 with RemoteControlClient

use of android.media.RemoteControlClient in project Timber by naman14.

the class MusicService method setUpRemoteControlClient.

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setUpRemoteControlClient() {
    // Legacy for ICS
    if (mRemoteControlClient == null) {
        Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
        mediaButtonIntent.setComponent(mMediaButtonReceiverComponent);
        PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0);
        // create and register the remote control client
        mRemoteControlClient = new RemoteControlClient(mediaPendingIntent);
        mAudioManager.registerRemoteControlClient(mRemoteControlClient);
    }
    mRemoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_STOP);
}
Also used : RemoteControlClient(android.media.RemoteControlClient) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) TargetApi(android.annotation.TargetApi)

Example 5 with RemoteControlClient

use of android.media.RemoteControlClient in project PlayerHater by chrisrhoden.

the class LockScreenControlsPlugin method getRemoteControlClient.

protected RemoteControlClient getRemoteControlClient() {
    if (mRemoteControlClient == null) {
        Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
        mediaButtonIntent.setComponent(getEventReceiver());
        PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), 0, mediaButtonIntent, PendingIntent.FLAG_CANCEL_CURRENT);
        mRemoteControlClient = new RemoteControlClient(pendingIntent);
    }
    return mRemoteControlClient;
}
Also used : RemoteControlClient(android.media.RemoteControlClient) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Aggregations

RemoteControlClient (android.media.RemoteControlClient)6 PendingIntent (android.app.PendingIntent)5 Intent (android.content.Intent)5 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 ComponentName (android.content.ComponentName)1 MediaSessionCompat (android.support.v4.media.session.MediaSessionCompat)1 MediaButtonIntentReceiver (org.moire.ultrasonic.receiver.MediaButtonIntentReceiver)1