summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/src/org/rockbox/RockboxPCM.java12
-rw-r--r--android/src/org/rockbox/RockboxService.java47
2 files changed, 43 insertions, 16 deletions
diff --git a/android/src/org/rockbox/RockboxPCM.java b/android/src/org/rockbox/RockboxPCM.java
index f098df6991..f2568d8406 100644
--- a/android/src/org/rockbox/RockboxPCM.java
+++ b/android/src/org/rockbox/RockboxPCM.java
@@ -56,9 +56,7 @@ public class RockboxPCM extends AudioTrack
56 LOG("setNotificationMarkerPosition Error"); 56 LOG("setNotificationMarkerPosition Error");
57 setPlaybackPositionUpdateListener(new PCMListener(buf_len*2)); 57 setPlaybackPositionUpdateListener(new PCMListener(buf_len*2));
58 } 58 }
59 } 59 }
60
61
62 60
63 int bytes2frames(int bytes) { 61 int bytes2frames(int bytes) {
64 /* 1 sample is 2 bytes, 2 samples are 1 frame */ 62 /* 1 sample is 2 bytes, 2 samples are 1 frame */
@@ -83,11 +81,19 @@ public class RockboxPCM extends AudioTrack
83 LOG("Writing silence"); 81 LOG("Writing silence");
84 /* fill with silence */ 82 /* fill with silence */
85 write(raw_data, 0, raw_data.length); 83 write(raw_data, 0, raw_data.length);
84 RockboxService.startForeground();
86 } 85 }
87 play(); 86 play();
88 } 87 }
89 LOG("play_pause() return"); 88 LOG("play_pause() return");
90 } 89 }
90
91 @Override
92 public void stop() throws IllegalStateException
93 {
94 super.stop();
95 RockboxService.stopForeground();
96 }
91 97
92 @SuppressWarnings("unused") 98 @SuppressWarnings("unused")
93 private void set_volume(int volume) 99 private void set_volume(int volume)
diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java
index 5c74d19ebf..216cd12e77 100644
--- a/android/src/org/rockbox/RockboxService.java
+++ b/android/src/org/rockbox/RockboxService.java
@@ -19,12 +19,16 @@ import android.util.Log;
19 19
20public class RockboxService extends Service 20public class RockboxService extends Service
21{ 21{
22 /* this Service is really a singleton class */
22 public static RockboxFramebuffer fb = null; 23 public static RockboxFramebuffer fb = null;
24 private static RockboxService instance;
25 private Notification notification;
23 @Override 26 @Override
24 public void onCreate() 27 public void onCreate()
25 { 28 {
26 mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 29 mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
27 startservice(); 30 startservice();
31 instance = this;
28 } 32 }
29 33
30 private void do_start(Intent intent) 34 private void do_start(Intent intent)
@@ -47,7 +51,7 @@ public class RockboxService extends Service
47 { 51 {
48 do_start(intent); 52 do_start(intent);
49 /* Display a notification about us starting. We put an icon in the status bar. */ 53 /* Display a notification about us starting. We put an icon in the status bar. */
50 showNotification(); 54 create_notification();
51 return START_STICKY; 55 return START_STICKY;
52 } 56 }
53 57
@@ -143,12 +147,14 @@ public class RockboxService extends Service
143 /* heavily based on the example found on 147 /* heavily based on the example found on
144 * http://developer.android.com/reference/android/app/Service.html 148 * http://developer.android.com/reference/android/app/Service.html
145 */ 149 */
146 public void showNotification() { 150
151 private void create_notification()
152 {
147 // In this sample, we'll use the same text for the ticker and the expanded notification 153 // In this sample, we'll use the same text for the ticker and the expanded notification
148 CharSequence text = getText(R.string.notification); 154 CharSequence text = getText(R.string.notification);
149 155
150 // Set the icon, scrolling text and timestamp 156 // Set the icon, scrolling text and timestamp
151 Notification notification = new Notification(R.drawable.rb, text, 157 notification = new Notification(R.drawable.rb, text,
152 System.currentTimeMillis()); 158 System.currentTimeMillis());
153 159
154 // The PendingIntent to launch our activity if the user selects this notification 160 // The PendingIntent to launch our activity if the user selects this notification
@@ -158,16 +164,31 @@ public class RockboxService extends Service
158 164
159 // Set the info for the views that show in the notification panel. 165 // Set the info for the views that show in the notification panel.
160 notification.setLatestEventInfo(this, getText(R.string.notification), text, contentIntent); 166 notification.setLatestEventInfo(this, getText(R.string.notification), text, contentIntent);
167 }
161 168
162 // Send the notification. 169 public static void startForeground()
163 // We use a layout id because it is a unique number. We use it later to cancel. 170 {
164 mNM.notify(R.string.notification, notification); 171 if (instance != null)
165 172 {
166 /* 173 // Send the notification.
167 * this call makes the service run as foreground, which 174 // We use a layout id because it is a unique number. We use it later to cancel.
168 * provides enough cpu time to do music decoding in the 175 instance.mNM.notify(R.string.notification, instance.notification);
169 * background 176
170 */ 177 /*
171 startForeground(R.string.notification, notification); 178 * this call makes the service run as foreground, which
179 * provides enough cpu time to do music decoding in the
180 * background
181 */
182 instance.startForeground(R.string.notification, instance.notification);
183 }
184 }
185
186 public static void stopForeground()
187 {
188 if (instance.notification != null)
189 {
190 instance.stopForeground(true);
191 instance.mNM.cancel(R.string.notification);
192 }
172 } 193 }
173} 194}