bherrmann7 / Car-Cast

Car Cast is a simple Android podcast downloader and player. Optimized for use in a daily commute, it features big buttons, large text, remembers last played location. FOR MORE INFO ---> http://jadn.com/cc/
http://jadn.com/cc/
57 stars 30 forks source link

Foreground mode #38

Closed andrm closed 13 years ago

andrm commented 13 years ago

Hi,

thanks for carcast, I'm using it everyday. Is there a reason why you don't use the android foreground mode? I have a Mot Milestone (Droid) which is a bit underpowered and if there is a lot happening on the device (navigation + general sync) sometimes CC gets stuttery or gets killed. There is the "Foreground mode" for apps in Android to improve scheduling for the app and avoid getting killed, specifically for things like music players. http://developer.android.com/reference/android/app/Service.html#startForeground%28int,%20android.app.Notification%29

Andreas.

bherrmann7 commented 13 years ago

What version of Android does the Mot Milestone run?

andrm commented 13 years ago

It's Android 2.2. MOT admitted this version not stellar, so it is quite sluggish in close to everything. It's not CC's "fault" per se, I was just interested what reason there is for not using foreground. Thanks!

baruch commented 13 years ago

This is a real issue for me, I use CarCast on the train so I like to read stuff and listen to the music podcast in the background, from time to time CC will just disappear and won't even save a bookmark for the last second so I'll have to go and search for the location. The worst part is that the music stopped in the first place.

baruch commented 13 years ago

Looking through the code there is an attempt to start as a foreground service, how can I help debug this?

bherrmann7 commented 13 years ago

Are we using it correctly? The google code in the first link did a fair amount of indirection to support many versions of android

baruch commented 13 years ago

I haven't done any android development so far so I dont know. I do know that CC doesn't show any notification icon on my system even when it is playing so something is probably not happening properly.

baruch commented 13 years ago

A quick code review that you do call stopForegroundCompat() but you never call startForegroundCompat. There are still calls sprinkled around for setForeground(true/false) that is deprecated in later APIs (2.0 and up actually).

bherrmann7 commented 13 years ago

OK, I desprinkled the setforeground stuff. I committed these changes to Git. Can you test them http://jadn.com/cc.apk. thx

bherrmann7 commented 13 years ago

Oops.. I should at least try this first

bherrmann7 commented 13 years ago

OK, now the version at http://jadn.com/cc.apk runs... can you try it out?

baruch commented 13 years ago

Still no notification icon upon playing, does it work for you? Do you see a notification icon?

baruch commented 13 years ago

I believe that calling the foreground task without a notification (a null notification) defeats the purpose, the idea from what I read so far is that there must be a notification icon for the user to know that something runs in the background.

baruch commented 13 years ago

I can't seem to install my own build of CC, this is the patch that is worth trying IMHO

$ git diff
diff --git a/cc/src/com/jadn/cc/services/ContentService.java b/cc/src/com/jadn/cc/services/ContentService.java
index adce0f1..c6daf0f 100644
--- a/cc/src/com/jadn/cc/services/ContentService.java
+++ b/cc/src/com/jadn/cc/services/ContentService.java
@@ -490,7 +490,9 @@ public class ContentService extends Service implements OnCompletionListener {
                headsetReceiver = new HeadsetReceiver(this);
                registerReceiver(headsetReceiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG));

-               startForegroundCompat(0,null);
+               Notification notification = new Notification();
+               notification.icon = R.drawable.ccp_launcher;
+               startForegroundCompat(0, notification);
        }

        public void headsetStatusChanged(boolean headsetPresent) {

I managed to install and it crashees, I have no USB cable to debug so it will have to wait for next week.

andrm commented 13 years ago

The lastest update shows the icon for foreground mode. This should fix the issue, I'm closing it. Thanks!