mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 20:30:41 +00:00
Bug 1282391 - make MediaControlService to foreground service when we're playing media. r=sebastian
MozReview-Commit-ID: HYN3PTQVdhG --HG-- extra : rebase_source : 5e9ad3fc90d0d04c72b5d5e0e958c174df056342
This commit is contained in:
parent
8046f55123
commit
a02e63bc63
@ -77,7 +77,7 @@ public class MediaControlService extends Service implements Tabs.OnTabsChangedLi
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
handleIntent(intent);
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -267,6 +267,7 @@ public class MediaControlService extends Service implements Tabs.OnTabsChangedLi
|
||||
final Notification.MediaStyle style = new Notification.MediaStyle();
|
||||
style.setShowActionsInCompactView(0);
|
||||
|
||||
final boolean isMediaPlaying = action.equals(ACTION_PAUSE);
|
||||
final Notification notification = new Notification.Builder(this)
|
||||
.setSmallIcon(R.drawable.flat_icon)
|
||||
.setLargeIcon(generateCoverArt(tab))
|
||||
@ -276,13 +277,18 @@ public class MediaControlService extends Service implements Tabs.OnTabsChangedLi
|
||||
.setDeleteIntent(createDeleteIntent())
|
||||
.setStyle(style)
|
||||
.addAction(createNotificationAction(action))
|
||||
.setOngoing(action.equals(ACTION_PAUSE))
|
||||
.setOngoing(isMediaPlaying)
|
||||
.setShowWhen(false)
|
||||
.setWhen(0)
|
||||
.build();
|
||||
|
||||
NotificationManagerCompat.from(this)
|
||||
if (isMediaPlaying) {
|
||||
startForeground(MEDIA_CONTROL_ID, notification);
|
||||
} else {
|
||||
stopForeground(false);
|
||||
NotificationManagerCompat.from(this)
|
||||
.notify(MEDIA_CONTROL_ID, notification);
|
||||
}
|
||||
}
|
||||
|
||||
private Notification.Action createNotificationAction(String action) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user