Skip to content
Permalink
Browse files

Fix play action

  • Loading branch information
ferjm committed Nov 13, 2019
1 parent 07483f1 commit 7b5b46f56071667a421a679a98812d755b63a4c7
@@ -232,12 +232,12 @@ public void onMediaSessionMetadata(String title, String artist, String album) {
if (mMediaSession == null) {
mMediaSession = new MediaSession(mServoView, this, getApplicationContext());
}
Log.d("SERVOMEDIA", "METADATA");
Log.d("onMediaSessionMetadata", title + " " + artist + " " + album);
}

@Override
public void onMediaSessionPlaybackStateChange(int state) {
Log.d("SERVOMEDIA", "PLAYBACK STATE CHANGED " + state);
Log.d("onMediaSessionPlaybackStateChange", String.valueOf(state));
if (mMediaSession == null) {
mMediaSession = new MediaSession(mServoView, this, getApplicationContext());
}
@@ -86,6 +86,7 @@ private void createMediaNotificationChannel() {
}

public void showMediaSessionControls(int playbackState) {
Log.d("MediaSession", "showMediaSessionControls " + playbackState);
IntentFilter filter = new IntentFilter();
if (playbackState == PLAYBACK_STATE_PAUSED) {
filter.addAction(KEY_MEDIA_PLAY);
@@ -95,21 +96,28 @@ public void showMediaSessionControls(int playbackState) {
}
filter.addAction(KEY_MEDIA_STOP);

mMediaSessionActionReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(KEY_MEDIA_PAUSE)) {
mView.mediaSessionAction(ACTION_PAUSE);
Log.d("SERVOMEDIA", "PAUSE");
} else if (intent.getAction().equals(KEY_MEDIA_PLAY)) {
mView.mediaSessionAction(ACTION_PLAY);
Log.d("SERVOMEDIA", "PLAY");
} else if (intent.getAction().equals(KEY_MEDIA_STOP)) {
mView.mediaSessionAction(ACTION_STOP);
Log.d("SERVOMEDIA", "STOP");
int id;
if (mMediaSessionActionReceiver == null) {
id = mNotificationID.getNext();

mMediaSessionActionReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(KEY_MEDIA_PAUSE)) {
mView.mediaSessionAction(ACTION_PAUSE);
Log.d("MediaSession", "PAUSE action");
} else if (intent.getAction().equals(KEY_MEDIA_PLAY)) {
mView.mediaSessionAction(ACTION_PLAY);
Log.d("MediaSession", "PLAY action");
} else if (intent.getAction().equals(KEY_MEDIA_STOP)) {
mView.mediaSessionAction(ACTION_STOP);
Log.d("MediaSession", "STOP action");
}
}
}
};
};
} else {
id = mNotificationID.get();
}

mContext.registerReceiver(mMediaSessionActionReceiver, filter);

@@ -144,14 +152,15 @@ public void onReceive(Context context, Intent intent) {

NotificationManager notificationManager =
mContext.getSystemService(NotificationManager.class);
notificationManager.notify(mNotificationID.getNext(), builder.build());
notificationManager.notify(id, builder.build());
}

public void hideMediaSessionControls() {
Log.d("SERVOMEDIA", "hideMediaSessionControls");
Log.d("MediaSession", "hideMediaSessionControls");
NotificationManager notificationManager =
mContext.getSystemService(NotificationManager.class);
notificationManager.cancel(mNotificationID.get());
mContext.unregisterReceiver(mMediaSessionActionReceiver);
mMediaSessionActionReceiver = null;
}
}

0 comments on commit 7b5b46f

Please sign in to comment.
You can’t perform that action at this time.