Android-x86
Fork
Faire un don

  • R/O
  • HTTP
  • SSH
  • HTTPS

packages-apps-Music: Commit

packages/apps/Music


Commit MetaInfo

Révisionaa331877dd1a0777042481e5c925cd951682588f (tree)
l'heure2010-04-21 09:00:26
AuteurJean-Michel Trivi <jmtrivi@goog...>
CommiterJean-Michel Trivi

Message de Log

Update the Music app to fully use AudioFocus to implement its logic
for pausing and resuming for phone rings and calls.
The Music app does no longer need to implement PhoneStateListener.

Change-Id: I9435969ec2ac7f755390136c3b689ec519742fa6

Change Summary

Modification

--- a/src/com/android/music/MediaPlaybackService.java
+++ b/src/com/android/music/MediaPlaybackService.java
@@ -137,7 +137,6 @@ public class MediaPlaybackService extends Service {
137137 private WakeLock mWakeLock;
138138 private int mServiceStartId = -1;
139139 private boolean mServiceInUse = false;
140- private boolean mResumeAfterCall = false;
141140 private boolean mIsSupposedToBePlaying = false;
142141 private boolean mQuietMode = false;
143142 private AudioManager mAudioManager;
@@ -152,33 +151,7 @@ public class MediaPlaybackService extends Service {
152151 private MediaAppWidgetProvider mAppWidgetProvider = MediaAppWidgetProvider.getInstance();
153152
154153 // interval after which we stop the service when idle
155- private static final int IDLE_DELAY = 60000;
156-
157- private PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
158- @Override
159- public void onCallStateChanged(int state, String incomingNumber) {
160- if (state == TelephonyManager.CALL_STATE_RINGING) {
161- AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
162- int ringvolume = audioManager.getStreamVolume(AudioManager.STREAM_RING);
163- mResumeAfterCall = (isPlaying() || mResumeAfterCall) && (getAudioId() >= 0);
164- if (ringvolume > 0) {
165- pause();
166- }
167- } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
168- // pause the music while a conversation is in progress
169- mResumeAfterCall = (isPlaying() || mResumeAfterCall) && (getAudioId() >= 0);
170- pause();
171- } else if (state == TelephonyManager.CALL_STATE_IDLE) {
172- // start playing again
173- if (mResumeAfterCall) {
174- // resume playback only if music was playing
175- // when the call was answered
176- startAndFadeIn();
177- mResumeAfterCall = false;
178- }
179- }
180- }
181- };
154+ private static final int IDLE_DELAY = 60000;
182155
183156 private void startAndFadeIn() {
184157 mMediaplayerHandler.sendEmptyMessageDelayed(FADEIN, 10);
@@ -250,16 +223,16 @@ public class MediaPlaybackService extends Service {
250223 } else if (CMDTOGGLEPAUSE.equals(cmd) || TOGGLEPAUSE_ACTION.equals(action)) {
251224 if (isPlaying()) {
252225 pause();
253- mResumeAfterCall = false;
226+ mPausedByTransientLossOfFocus = false;
254227 } else {
255228 play();
256229 }
257230 } else if (CMDPAUSE.equals(cmd) || PAUSE_ACTION.equals(action)) {
258231 pause();
259- mResumeAfterCall = false;
232+ mPausedByTransientLossOfFocus = false;
260233 } else if (CMDSTOP.equals(cmd)) {
261234 pause();
262- mResumeAfterCall = false;
235+ mPausedByTransientLossOfFocus = false;
263236 seek(0);
264237 } else if (MediaAppWidgetProvider.CMDAPPWIDGETUPDATE.equals(cmd)) {
265238 // Someone asked us to refresh a set of specific widgets, probably
@@ -293,7 +266,7 @@ public class MediaPlaybackService extends Service {
293266 Log.v(LOGTAG, "AudioFocus: received AUDIOFOCUS_GAIN");
294267 if(!isPlaying() && mPausedByTransientLossOfFocus) {
295268 mPausedByTransientLossOfFocus = false;
296- play();
269+ startAndFadeIn();
297270 }
298271 break;
299272 default:
@@ -333,8 +306,6 @@ public class MediaPlaybackService extends Service {
333306 commandFilter.addAction(PREVIOUS_ACTION);
334307 registerReceiver(mIntentReceiver, commandFilter);
335308
336- TelephonyManager tmgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
337- tmgr.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
338309 PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
339310 mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
340311 mWakeLock.setReferenceCounted(false);
@@ -367,9 +338,6 @@ public class MediaPlaybackService extends Service {
367338 mCursor = null;
368339 }
369340
370- TelephonyManager tmgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
371- tmgr.listen(mPhoneStateListener, 0);
372-
373341 unregisterReceiver(mIntentReceiver);
374342 if (mUnmountReceiver != null) {
375343 unregisterReceiver(mUnmountReceiver);
@@ -634,16 +602,16 @@ public class MediaPlaybackService extends Service {
634602 } else if (CMDTOGGLEPAUSE.equals(cmd) || TOGGLEPAUSE_ACTION.equals(action)) {
635603 if (isPlaying()) {
636604 pause();
637- mResumeAfterCall = false;
605+ mPausedByTransientLossOfFocus = false;
638606 } else {
639607 play();
640608 }
641609 } else if (CMDPAUSE.equals(cmd) || PAUSE_ACTION.equals(action)) {
642610 pause();
643- mResumeAfterCall = false;
611+ mPausedByTransientLossOfFocus = false;
644612 } else if (CMDSTOP.equals(cmd)) {
645613 pause();
646- mResumeAfterCall = false;
614+ mPausedByTransientLossOfFocus = false;
647615 seek(0);
648616 }
649617 }
@@ -663,9 +631,9 @@ public class MediaPlaybackService extends Service {
663631 // Take a snapshot of the current playlist
664632 saveQueue(true);
665633
666- if (isPlaying() || mResumeAfterCall) {
634+ if (isPlaying() || mPausedByTransientLossOfFocus) {
667635 // something is currently playing, or will be playing once
668- // an in-progress call ends, so don't stop the service now.
636+ // an in-progress action requesting audio focus ends, so don't stop the service now.
669637 return true;
670638 }
671639
@@ -687,7 +655,7 @@ public class MediaPlaybackService extends Service {
687655 @Override
688656 public void handleMessage(Message msg) {
689657 // Check again to make sure nothing is playing right now
690- if (isPlaying() || mResumeAfterCall || mServiceInUse
658+ if (isPlaying() || mPausedByTransientLossOfFocus || mServiceInUse
691659 || mMediaplayerHandler.hasMessages(TRACK_ENDED)) {
692660 return;
693661 }
Afficher sur ancien navigateur de dépôt.