Keep the notification around even after pausing

This commit is contained in:
Christopher Eby 2010-02-21 00:29:10 -06:00
parent d1be1d80cc
commit 69251f2aa6

View File

@ -11,6 +11,7 @@ import java.util.ArrayList;
import java.util.Random; import java.util.Random;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
@ -212,12 +213,12 @@ public class MusicPlayer implements Runnable, MediaPlayer.OnCompletionListener,
mWakeLock.release(); mWakeLock.release();
break; break;
case HANDLE_PLAY: case HANDLE_PLAY:
mService.startForegroundCompat(NOTIFICATION_ID, createNotfication());
setState(STATE_PLAYING); setState(STATE_PLAYING);
mService.startForegroundCompat(NOTIFICATION_ID, createNotification());
break; break;
case HANDLE_PAUSE: case HANDLE_PAUSE:
mService.stopForegroundCompat(NOTIFICATION_ID);
setState(STATE_NORMAL); setState(STATE_NORMAL);
mService.stopForegroundCompat(0);
break; break;
case RETRIEVE_SONGS: case RETRIEVE_SONGS:
retrieveSongs(); retrieveSongs();
@ -225,7 +226,7 @@ public class MusicPlayer implements Runnable, MediaPlayer.OnCompletionListener,
case REMOTE_PLAYER_PREF_CHANGED: case REMOTE_PLAYER_PREF_CHANGED:
mUseRemotePlayer = message.arg1 == 1; mUseRemotePlayer = message.arg1 == 1;
if (mState == STATE_PLAYING) if (mState == STATE_PLAYING)
mService.startForegroundCompat(NOTIFICATION_ID, createNotfication()); mService.startForegroundCompat(NOTIFICATION_ID, createNotification());
break; break;
} }
} }
@ -251,7 +252,10 @@ public class MusicPlayer implements Runnable, MediaPlayer.OnCompletionListener,
settings.registerOnSharedPreferenceChangeListener(this); settings.registerOnSharedPreferenceChangeListener(this);
setCurrentSong(1); setCurrentSong(1);
NotificationManager manager = (NotificationManager)mService.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(NOTIFICATION_ID, createNotification());
Looper.loop(); Looper.loop();
} }
@ -296,8 +300,8 @@ public class MusicPlayer implements Runnable, MediaPlayer.OnCompletionListener,
setState(STATE_NORMAL); setState(STATE_NORMAL);
} }
} }
private Notification createNotfication() private Notification createNotification()
{ {
Song song = getSong(0); Song song = getSong(0);