cancel chapter loader thread if service receives shutdown notification

This commit is contained in:
daniel oeh 2012-09-25 14:12:59 +02:00
parent e206d1571f
commit 6904ea23a6
1 changed files with 9 additions and 1 deletions

View File

@ -134,6 +134,8 @@ public class PlaybackService extends Service {
private SleepTimer sleepTimer; private SleepTimer sleepTimer;
private Future sleepTimerFuture; private Future sleepTimerFuture;
private Thread chapterLoader;
private static final int SCHED_EX_POOL_SIZE = 3; private static final int SCHED_EX_POOL_SIZE = 3;
private ScheduledThreadPoolExecutor schedExecutor; private ScheduledThreadPoolExecutor schedExecutor;
@ -556,7 +558,10 @@ public class PlaybackService extends Service {
} }
if (shouldStream && media.getItem().getChapters() == null) { if (shouldStream && media.getItem().getChapters() == null) {
// load chapters if available // load chapters if available
Thread chapterLoader = new Thread() { if (chapterLoader != null) {
chapterLoader.interrupt();
}
chapterLoader = new Thread() {
@Override @Override
public void run() { public void run() {
@ -1004,6 +1009,9 @@ public class PlaybackService extends Service {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION_SHUTDOWN_PLAYBACK_SERVICE)) { if (intent.getAction().equals(ACTION_SHUTDOWN_PLAYBACK_SERVICE)) {
schedExecutor.shutdownNow(); schedExecutor.shutdownNow();
if (chapterLoader != null) {
chapterLoader.interrupt();
}
stop(); stop();
media = null; media = null;
feed = null; feed = null;