mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Fix play action
This commit is contained in:
parent
07483f1d44
commit
7b5b46f560
2 changed files with 27 additions and 18 deletions
|
@ -232,12 +232,12 @@ public class MainActivity extends Activity implements Servo.Client {
|
|||
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 @@ public class MediaSession {
|
|||
}
|
||||
|
||||
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 class MediaSession {
|
|||
}
|
||||
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 class MediaSession {
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue