Skip to content
Snippets Groups Projects
Commit eb846cff authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Reduce calls of startService in PlaybackService

parent 8ee4529d
No related branches found
No related tags found
No related merge requests found
...@@ -242,7 +242,6 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo ...@@ -242,7 +242,6 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
hideNotification();
mSettings = PreferenceManager.getDefaultSharedPreferences(this); mSettings = PreferenceManager.getDefaultSharedPreferences(this);
mMediaPlayer = newMediaPlayer(); mMediaPlayer = newMediaPlayer();
mMediaPlayer.setEqualizer(VLCOptions.getEqualizerSetFromSettings(this)); mMediaPlayer.setEqualizer(VLCOptions.getEqualizerSetFromSettings(this));
...@@ -353,7 +352,7 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo ...@@ -353,7 +352,7 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
stop(); stop(true);
if (mMediaSession != null) { if (mMediaSession != null) {
mMediaSession.setActive(false); mMediaSession.setActive(false);
mMediaSession.release(); mMediaSession.release();
...@@ -719,7 +718,6 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo ...@@ -719,7 +718,6 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
mMedialibrary.resumeBackgroundOperations(); mMedialibrary.resumeBackgroundOperations();
mStopped = true; mStopped = true;
mCurrentIndex = -1; mCurrentIndex = -1;
hideNotification();
executeUpdate(); executeUpdate();
publishState(); publishState();
executeUpdateProgress(); executeUpdateProgress();
...@@ -967,10 +965,17 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo ...@@ -967,10 +965,17 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
cover, playing, sessionToken, getSessionPendingIntent()); cover, playing, sessionToken, getSessionPendingIntent());
if (isPlayingPopup()) if (isPlayingPopup())
return; return;
if (AndroidUtil.isOOrLater || !AndroidUtil.isLolliPopOrLater || playing) if (AndroidUtil.isOOrLater || !AndroidUtil.isLolliPopOrLater || playing) {
PlaybackService.this.startForeground(3, notification); if (!mIsForeground) {
else { PlaybackService.this.startForeground(3, notification);
PlaybackService.this.stopForeground(false); mIsForeground = true;
} else
NotificationManagerCompat.from(ctx).notify(3, notification);
} else {
if (mIsForeground) {
PlaybackService.this.stopForeground(false);
mIsForeground = false;
}
NotificationManagerCompat.from(ctx).notify(3, notification); NotificationManagerCompat.from(ctx).notify(3, notification);
} }
} catch (IllegalArgumentException e){ } catch (IllegalArgumentException e){
...@@ -999,12 +1004,15 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo ...@@ -999,12 +1004,15 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
} }
} }
private volatile boolean mIsForeground = false;
private void hideNotification() { private void hideNotification() {
mExecutorService.execute(new Runnable() { mExecutorService.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
if (!isPlayingPopup()) if (!isPlayingPopup() && mIsForeground) {
PlaybackService.this.stopForeground(true); PlaybackService.this.stopForeground(true);
mIsForeground = false;
}
NotificationManagerCompat.from(PlaybackService.this).cancel(3); NotificationManagerCompat.from(PlaybackService.this).cancel(3);
} }
}); });
...@@ -1026,6 +1034,11 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo ...@@ -1026,6 +1034,11 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
@MainThread @MainThread
public void stop() { public void stop() {
stop(false);
}
@MainThread
public void stop(boolean systemExit) {
removePopup(); removePopup();
if (mMediaPlayer == null) if (mMediaPlayer == null)
return; return;
...@@ -1041,6 +1054,8 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo ...@@ -1041,6 +1054,8 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
mPrevious.clear(); mPrevious.clear();
mHandler.removeMessages(SHOW_PROGRESS); mHandler.removeMessages(SHOW_PROGRESS);
onPlaybackStopped(); onPlaybackStopped();
if (!systemExit)
hideNotification();
} }
private void determinePrevAndNextIndices() { private void determinePrevAndNextIndices() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment