Made sure PlaybackService only reacts to transient audio focus loss if

it's in the PLAYING state
This commit is contained in:
daniel oeh 2012-09-14 14:34:46 +02:00
parent 71f948cafa
commit 9f25077b94

View File

@ -276,19 +276,23 @@ public class PlaybackService extends Service {
} }
break; break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK: case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
if (status == PlayerStatus.PLAYING) {
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "Lost audio focus temporarily. Ducking..."); Log.d(TAG, "Lost audio focus temporarily. Ducking...");
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_LOWER, 0); AudioManager.ADJUST_LOWER, 0);
pausedBecauseOfTransientAudiofocusLoss = true; pausedBecauseOfTransientAudiofocusLoss = true;
}
break; break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
if (status == PlayerStatus.PLAYING) {
if (AppConfig.DEBUG) if (AppConfig.DEBUG)
Log.d(TAG, "Lost audio focus temporarily. Pausing..."); Log.d(TAG, "Lost audio focus temporarily. Pausing...");
pause(false); pause(false);
pausedBecauseOfTransientAudiofocusLoss = true; pausedBecauseOfTransientAudiofocusLoss = true;
} }
} }
}
}; };
@Override @Override
@ -722,9 +726,11 @@ public class PlaybackService extends Service {
Bitmap icon = BitmapFactory.decodeResource(null, Bitmap icon = BitmapFactory.decodeResource(null,
R.drawable.ic_stat_antenna); R.drawable.ic_stat_antenna);
notificationBuilder = new NotificationCompat.Builder(this) notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle(getString(R.string.playbackservice_notification_title)) .setContentTitle(
.setContentText(getString(R.string.playbackservice_notification_content)).setOngoing(true) getString(R.string.playbackservice_notification_title))
.setContentIntent(pIntent).setLargeIcon(icon) .setContentText(
getString(R.string.playbackservice_notification_content))
.setOngoing(true).setContentIntent(pIntent).setLargeIcon(icon)
.setSmallIcon(R.drawable.ic_stat_antenna); .setSmallIcon(R.drawable.ic_stat_antenna);
startForeground(NOTIFICATION_ID, notificationBuilder.getNotification()); startForeground(NOTIFICATION_ID, notificationBuilder.getNotification());