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);
}
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);
}
}
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);
}
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);
}
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;
}
Aggregations