summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/service/PlaybackService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/danoeh/antennapod/service/PlaybackService.java')
-rw-r--r--src/de/danoeh/antennapod/service/PlaybackService.java53
1 files changed, 27 insertions, 26 deletions
diff --git a/src/de/danoeh/antennapod/service/PlaybackService.java b/src/de/danoeh/antennapod/service/PlaybackService.java
index 341245cf9..7a32d7786 100644
--- a/src/de/danoeh/antennapod/service/PlaybackService.java
+++ b/src/de/danoeh/antennapod/service/PlaybackService.java
@@ -24,6 +24,7 @@ import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.view.KeyEvent;
import android.view.SurfaceHolder;
+import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MediaplayerActivity;
@@ -110,7 +111,7 @@ public class PlaybackService extends Service {
isRunning = true;
pausedBecauseOfTransientAudiofocusLoss = false;
status = PlayerStatus.STOPPED;
- Log.d(TAG, "Service created.");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Service created.");
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
manager = FeedManager.getInstance();
player = new MediaPlayer();
@@ -132,7 +133,7 @@ public class PlaybackService extends Service {
super.onDestroy();
isRunning = false;
unregisterReceiver(headsetDisconnected);
- Log.d(TAG, "Service is about to be destroyed");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Service is about to be destroyed");
audioManager.unregisterMediaButtonEventReceiver(mediaButtonReceiver);
audioManager.abandonAudioFocus(audioFocusChangeListener);
player.release();
@@ -151,24 +152,24 @@ public class PlaybackService extends Service {
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_LOSS:
- Log.d(TAG, "Lost audio focus");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Lost audio focus");
pause(true);
stopSelf();
break;
case AudioManager.AUDIOFOCUS_GAIN:
- Log.d(TAG, "Gained audio focus");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Gained audio focus");
if (pausedBecauseOfTransientAudiofocusLoss) {
play();
}
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
- Log.d(TAG, "Lost audio focus temporarily. Ducking...");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Lost audio focus temporarily. Ducking...");
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_LOWER, 0);
pausedBecauseOfTransientAudiofocusLoss = true;
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
- Log.d(TAG, "Lost audio focus temporarily. Pausing...");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Lost audio focus temporarily. Pausing...");
pause(false);
pausedBecauseOfTransientAudiofocusLoss = true;
}
@@ -179,7 +180,7 @@ public class PlaybackService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
int keycode = intent.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1);
if (keycode != -1) {
- Log.d(TAG, "Received media button event");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Received media button event");
handleKeycode(keycode);
} else {
@@ -256,7 +257,7 @@ public class PlaybackService extends Service {
* mediaplayer.
*/
public void setVideoSurface(SurfaceHolder sh) {
- Log.d(TAG, "Setting display");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Setting display");
player.setDisplay(null);
player.setDisplay(sh);
if (status == PlayerStatus.STOPPED
@@ -359,7 +360,7 @@ public class PlaybackService extends Service {
private MediaPlayer.OnPreparedListener preparedListener = new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
- Log.d(TAG, "Resource prepared");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Resource prepared");
mp.seekTo(media.getPosition());
setStatus(PlayerStatus.PREPARED);
if (startWhenPrepared) {
@@ -398,7 +399,7 @@ public class PlaybackService extends Service {
@Override
public void onCompletion(MediaPlayer mp) {
- Log.d(TAG, "Playback completed");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Playback completed");
// Save state
positionSaver.cancel(true);
media.setPosition(0);
@@ -415,14 +416,14 @@ public class PlaybackService extends Service {
.getBoolean(PodcastApp.PREF_FOLLOW_QUEUE, false);
FeedItem nextItem = manager.getFirstQueueItem();
if (isInQueue && followQueue && nextItem != null) {
- Log.d(TAG, "Loading next item in queue");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Loading next item in queue");
media = nextItem.getMedia();
feed = nextItem.getFeed();
shouldStream = !media.isDownloaded();
resetVideoSurface();
sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0);
} else {
- Log.d(TAG, "Stopping playback");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Stopping playback");
stopWidgetUpdater();
setStatus(PlayerStatus.STOPPED);
stopForeground(true);
@@ -448,7 +449,7 @@ public class PlaybackService extends Service {
*/
public void pause(boolean abandonFocus) {
if (player.isPlaying()) {
- Log.d(TAG, "Pausing playback.");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Pausing playback.");
player.pause();
if (abandonFocus) {
audioManager.abandonAudioFocus(audioFocusChangeListener);
@@ -477,8 +478,8 @@ public class PlaybackService extends Service {
AudioManager.AUDIOFOCUS_GAIN);
if (focusGained == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
- Log.d(TAG, "Audiofocus successfully requested");
- Log.d(TAG, "Resuming/Starting playback");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Audiofocus successfully requested");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Resuming/Starting playback");
SharedPreferences.Editor editor = getApplicationContext()
.getSharedPreferences(PodcastApp.PREF_NAME, 0).edit();
editor.putLong(PREF_LAST_PLAYED_ID, media.getId());
@@ -494,13 +495,13 @@ public class PlaybackService extends Service {
setupNotification();
pausedBecauseOfTransientAudiofocusLoss = false;
} else {
- Log.d(TAG, "Failed to request Audiofocus");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Failed to request Audiofocus");
}
}
}
private void setStatus(PlayerStatus newStatus) {
- Log.d(TAG, "Setting status to " + newStatus);
+ if (BuildConfig.DEBUG) Log.d(TAG, "Setting status to " + newStatus);
status = newStatus;
sendBroadcast(new Intent(ACTION_PLAYER_STATUS_CHANGED));
updateWidget();
@@ -528,7 +529,7 @@ public class PlaybackService extends Service {
.setSmallIcon(R.drawable.ic_stat_antenna);
startForeground(NOTIFICATION_ID, notificationBuilder.getNotification());
- Log.d(TAG, "Notification set up");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Notification set up");
}
/**
@@ -542,7 +543,7 @@ public class PlaybackService extends Service {
}
public void seek(int i) {
- Log.d(TAG, "Seeking position " + i);
+ if (BuildConfig.DEBUG) Log.d(TAG, "Seeking position " + i);
if (shouldStream) {
statusBeforeSeek = status;
setStatus(PlayerStatus.SEEKING);
@@ -553,7 +554,7 @@ public class PlaybackService extends Service {
/** Saves the current position of the media file to the DB */
private synchronized void saveCurrentPosition() {
- Log.d(TAG, "Saving current position to " + player.getCurrentPosition());
+ if (BuildConfig.DEBUG) Log.d(TAG, "Saving current position to " + player.getCurrentPosition());
media.setPosition(player.getCurrentPosition());
manager.setFeedMedia(this, media);
}
@@ -576,7 +577,7 @@ public class PlaybackService extends Service {
}
private void updateWidget() {
- Log.d(TAG, "Sending widget update request");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Sending widget update request");
PlaybackService.this.sendBroadcast(new Intent(
PlayerWidget.FORCE_WIDGET_UPDATE));
}
@@ -594,18 +595,18 @@ public class PlaybackService extends Service {
if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
int state = intent.getIntExtra("state", -1);
if (state != -1) {
- Log.d(TAG, "Headset plug event. State is " + state);
+ if (BuildConfig.DEBUG) Log.d(TAG, "Headset plug event. State is " + state);
boolean pauseOnDisconnect = PreferenceManager
.getDefaultSharedPreferences(
getApplicationContext())
.getBoolean(
PodcastApp.PREF_PAUSE_ON_HEADSET_DISCONNECT,
false);
- Log.d(TAG, "pauseOnDisconnect preference is "
+ if (BuildConfig.DEBUG) Log.d(TAG, "pauseOnDisconnect preference is "
+ pauseOnDisconnect);
if (state == UNPLUGGED && pauseOnDisconnect
&& status == PlayerStatus.PLAYING) {
- Log.d(TAG,
+ if (BuildConfig.DEBUG) Log.d(TAG,
"Pausing playback because headset was disconnected");
pause(true);
}
@@ -627,11 +628,11 @@ public class PlaybackService extends Service {
Thread.sleep(WAITING_INTERVALL);
saveCurrentPosition();
} catch (InterruptedException e) {
- Log.d(TAG,
+ if (BuildConfig.DEBUG) Log.d(TAG,
"Thread was interrupted while waiting. Finishing now...");
return null;
} catch (IllegalStateException e) {
- Log.d(TAG, "Player is in illegal state. Finishing now");
+ if (BuildConfig.DEBUG) Log.d(TAG, "Player is in illegal state. Finishing now");
return null;
}