summaryrefslogtreecommitdiff
path: root/src/de
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-07-23 01:30:57 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-07-23 01:30:57 +0200
commit81e03efc3d195d391e4819fd6b795e26e0671e78 (patch)
tree25ad570d74f751c491380c5170b3f176449c502e /src/de
parentea2c8e6e4b161dc2af5c5054590d70ae6178aca5 (diff)
downloadAntennaPod-81e03efc3d195d391e4819fd6b795e26e0671e78.zip
implemented chapterlist in mediaplayer
Diffstat (limited to 'src/de')
-rw-r--r--src/de/danoeh/antennapod/activity/MediaplayerActivity.java128
-rw-r--r--src/de/danoeh/antennapod/service/PlaybackService.java90
-rw-r--r--src/de/danoeh/antennapod/storage/PodDBAdapter.java2
3 files changed, 160 insertions, 60 deletions
diff --git a/src/de/danoeh/antennapod/activity/MediaplayerActivity.java b/src/de/danoeh/antennapod/activity/MediaplayerActivity.java
index f5496a9da..ffed9f0f0 100644
--- a/src/de/danoeh/antennapod/activity/MediaplayerActivity.java
+++ b/src/de/danoeh/antennapod/activity/MediaplayerActivity.java
@@ -28,14 +28,17 @@ import android.view.SurfaceHolder;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
+import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.LinearLayout;
+import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.VideoView;
import com.actionbarsherlock.app.SherlockFragmentActivity;
+import com.actionbarsherlock.app.SherlockListFragment;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
@@ -44,8 +47,10 @@ import com.viewpagerindicator.TabPageIndicator;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.PodcastApp;
import de.danoeh.antennapod.R;
+import de.danoeh.antennapod.adapter.SCListAdapter;
import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.feed.FeedMedia;
+import de.danoeh.antennapod.feed.SimpleChapter;
import de.danoeh.antennapod.fragment.CoverFragment;
import de.danoeh.antennapod.fragment.ItemDescriptionFragment;
import de.danoeh.antennapod.service.PlaybackService;
@@ -98,7 +103,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
@Override
protected void onStop() {
super.onStop();
- if (AppConfig.DEBUG) Log.d(TAG, "Activity stopped");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Activity stopped");
try {
unregisterReceiver(statusUpdate);
} catch (IllegalArgumentException e) {
@@ -157,7 +163,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
@Override
protected void onResume() {
super.onResume();
- if (AppConfig.DEBUG) Log.d(TAG, "Resuming Activity");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Resuming Activity");
StorageUtils.checkStorageAvailability(this);
bindToService();
@@ -166,7 +173,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
- if (AppConfig.DEBUG) Log.d(TAG, "Configuration changed");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Configuration changed");
orientation = newConfig.orientation;
if (positionObserver != null) {
positionObserver.cancel(true);
@@ -192,7 +200,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- if (AppConfig.DEBUG) Log.d(TAG, "Creating Activity");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Creating Activity");
StorageUtils.checkStorageAvailability(this);
orientation = getResources().getConfiguration().orientation;
@@ -206,7 +215,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
Intent serviceIntent = new Intent(this, PlaybackService.class);
boolean bound = false;
if (!PlaybackService.isRunning) {
- if (AppConfig.DEBUG) Log.d(TAG, "Trying to restore last played media");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Trying to restore last played media");
SharedPreferences prefs = getApplicationContext()
.getSharedPreferences(PodcastApp.PREF_NAME, 0);
long mediaId = prefs.getLong(PlaybackService.PREF_LAST_PLAYED_ID,
@@ -225,7 +235,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
bound = bindService(serviceIntent, mConnection,
Context.BIND_AUTO_CREATE);
} else {
- if (AppConfig.DEBUG) Log.d(TAG, "No last played media found");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "No last played media found");
status = PlayerStatus.STOPPED;
setupGUI();
handleStatus();
@@ -233,7 +244,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
} else {
bound = bindService(serviceIntent, mConnection, 0);
}
- if (AppConfig.DEBUG) Log.d(TAG, "Result for service binding: " + bound);
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Result for service binding: " + bound);
}
private void handleStatus() {
@@ -273,7 +285,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
setStatusMsg(R.string.player_seeking_msg, View.VISIBLE);
break;
case AWAITING_VIDEO_SURFACE:
- if (AppConfig.DEBUG) Log.d(TAG, "Preparing video playback");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Preparing video playback");
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
@@ -290,7 +303,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
@SuppressLint("NewApi")
private void setupPositionObserver() {
if (positionObserver == null || positionObserver.isCancelled()) {
- if (AppConfig.DEBUG) Log.d(TAG, "Setting up position observer");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Setting up position observer");
positionObserver = new MediaPositionObserver() {
@Override
@@ -303,6 +317,7 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
.getDurationStringLong(playbackService.getPlayer()
.getDuration()));
updateProgressbarPosition();
+ pagerAdapter.notifyMediaPositionChanged();
}
};
@@ -318,7 +333,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
}
private void updateProgressbarPosition() {
- if (AppConfig.DEBUG) Log.d(TAG, "Updating progressbar info");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Updating progressbar info");
MediaPlayer player = playbackService.getPlayer();
float progress = ((float) player.getCurrentPosition())
/ player.getDuration();
@@ -327,7 +343,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
private void loadMediaInfo() {
if (!mediaInfoLoaded) {
- if (AppConfig.DEBUG) Log.d(TAG, "Loading media info");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Loading media info");
if (media != null) {
getSupportActionBar().setSubtitle(media.getItem().getTitle());
getSupportActionBar().setTitle(
@@ -424,8 +441,13 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
txtvStatus = (TextView) findViewById(R.id.txtvStatus);
viewpager = (ViewPager) findViewById(R.id.viewpager);
tabs = (TabPageIndicator) findViewById(R.id.tabs);
+
+ int tabcount = 2;
+ if (media != null && media.getItem().getSimpleChapters() != null) {
+ tabcount = 3;
+ }
pagerAdapter = new MediaPlayerPagerAdapter(
- getSupportFragmentManager(), 2, this);
+ getSupportFragmentManager(), tabcount, this);
viewpager.setAdapter(pagerAdapter);
tabs.setViewPager(viewpager);
} else {
@@ -479,8 +501,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
}
videoControlsToggler = new VideoControlsHider();
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
- videoControlsToggler.executeOnExecutor(
- AsyncTask.THREAD_POOL_EXECUTOR);
+ videoControlsToggler
+ .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
videoControlsToggler.execute();
}
@@ -525,13 +547,15 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
PlaybackService.ACTION_PLAYER_NOTIFICATION));
queryService();
- if (AppConfig.DEBUG) Log.d(TAG, "Connection to Service established");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Connection to Service established");
}
@Override
public void onServiceDisconnected(ComponentName name) {
playbackService = null;
- if (AppConfig.DEBUG) Log.d(TAG, "Disconnected from Service");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Disconnected from Service");
}
};
@@ -541,7 +565,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
* information has to be refreshed
*/
private void queryService() {
- if (AppConfig.DEBUG) Log.d(TAG, "Querying service info");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Querying service info");
if (playbackService != null) {
int requestedOrientation;
status = playbackService.getStatus();
@@ -558,12 +583,14 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
// check if orientation is correct
if ((requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE && orientation == Configuration.ORIENTATION_LANDSCAPE)
|| (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT && orientation == Configuration.ORIENTATION_PORTRAIT)) {
- if (AppConfig.DEBUG) Log.d(TAG, "Orientation correct");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Orientation correct");
setupGUI();
handleStatus();
} else {
- if (AppConfig.DEBUG) Log.d(TAG,
- "Orientation incorrect, waiting for orientation change");
+ if (AppConfig.DEBUG)
+ Log.d(TAG,
+ "Orientation incorrect, waiting for orientation change");
}
} else {
Log.e(TAG,
@@ -574,7 +601,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
private BroadcastReceiver statusUpdate = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- if (AppConfig.DEBUG) Log.d(TAG, "Received statusUpdate Intent.");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Received statusUpdate Intent.");
status = playbackService.getStatus();
handleStatus();
}
@@ -612,7 +640,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
}
} else {
- if (AppConfig.DEBUG) Log.d(TAG, "Bad arguments. Won't handle intent");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Bad arguments. Won't handle intent");
}
}
@@ -630,7 +659,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
@Override
public void surfaceCreated(SurfaceHolder holder) {
holderCreated = true;
- if (AppConfig.DEBUG) Log.d(TAG, "Videoview holder created");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Videoview holder created");
if (status == PlayerStatus.AWAITING_VIDEO_SURFACE) {
if (playbackService != null) {
playbackService.setVideoSurface(holder);
@@ -652,6 +682,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
private int numItems;
private MediaplayerActivity activity;
+ private SherlockListFragment sCChapterFragment;
+
private static final int POS_COVER = 0;
private static final int POS_DESCR = 1;
private static final int POS_CHAPTERS = 2;
@@ -675,6 +707,26 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
activity.descriptionFragment = ItemDescriptionFragment
.newInstance(activity.media.getItem(), true);
return activity.descriptionFragment;
+ case POS_CHAPTERS:
+ sCChapterFragment = new SherlockListFragment() {
+
+ @Override
+ public void onListItemClick(ListView l, View v,
+ int position, long id) {
+ super.onListItemClick(l, v, position, id);
+ SimpleChapter chapter = (SimpleChapter) this
+ .getListAdapter().getItem(position);
+ if (activity.playbackService != null) {
+ activity.playbackService.seekToChapter(chapter);
+ }
+ }
+
+ };
+
+ sCChapterFragment.setListAdapter(new SCListAdapter(
+ activity, 0, activity.media.getItem()
+ .getSimpleChapters()));
+ return sCChapterFragment;
default:
return CoverFragment.newInstance(null);
}
@@ -690,6 +742,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
return activity.getString(R.string.cover_label);
case POS_DESCR:
return activity.getString(R.string.description_label);
+ case POS_CHAPTERS:
+ return activity.getString(R.string.chapters_label);
default:
return super.getPageTitle(position);
}
@@ -705,6 +759,14 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
return POSITION_UNCHANGED;
}
+ public void notifyMediaPositionChanged() {
+ if (sCChapterFragment != null) {
+ ArrayAdapter<SimpleChapter> adapter = (ArrayAdapter<SimpleChapter>) sCChapterFragment
+ .getListAdapter();
+ adapter.notifyDataSetChanged();
+ }
+ }
+
}
// ---------------------- ASYNC TASKS
@@ -719,29 +781,34 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
@Override
protected void onCancelled() {
- if (AppConfig.DEBUG) Log.d(TAG, "Task was cancelled");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Task was cancelled");
}
@Override
protected Void doInBackground(MediaPlayer... p) {
- if (AppConfig.DEBUG) Log.d(TAG, "Background Task started");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Background Task started");
player = p[0];
try {
while (player.isPlaying() && !isCancelled()) {
try {
Thread.sleep(WAITING_INTERVALL);
} catch (InterruptedException e) {
- if (AppConfig.DEBUG) Log.d(TAG,
- "Thread was interrupted while waiting. Finishing now");
+ if (AppConfig.DEBUG)
+ Log.d(TAG,
+ "Thread was interrupted while waiting. Finishing now");
return null;
}
publishProgress();
}
} catch (IllegalStateException e) {
- if (AppConfig.DEBUG) Log.d(TAG, "player is in illegal state, exiting now");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "player is in illegal state, exiting now");
}
- if (AppConfig.DEBUG) Log.d(TAG, "Background Task finished");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Background Task finished");
return null;
}
}
@@ -764,7 +831,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
@Override
protected void onProgressUpdate(Void... values) {
if (videoControlsShowing) {
- if (AppConfig.DEBUG) Log.d(TAG, "Hiding video controls");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Hiding video controls");
getSupportActionBar().hide();
videoOverlay.setVisibility(View.GONE);
videoControlsShowing = false;
diff --git a/src/de/danoeh/antennapod/service/PlaybackService.java b/src/de/danoeh/antennapod/service/PlaybackService.java
index a6633204f..f991ffbe1 100644
--- a/src/de/danoeh/antennapod/service/PlaybackService.java
+++ b/src/de/danoeh/antennapod/service/PlaybackService.java
@@ -32,6 +32,7 @@ import de.danoeh.antennapod.feed.Feed;
import de.danoeh.antennapod.feed.FeedItem;
import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.feed.FeedMedia;
+import de.danoeh.antennapod.feed.SimpleChapter;
import de.danoeh.antennapod.receiver.MediaButtonReceiver;
import de.danoeh.antennapod.receiver.PlayerWidget;
@@ -111,7 +112,8 @@ public class PlaybackService extends Service {
isRunning = true;
pausedBecauseOfTransientAudiofocusLoss = false;
status = PlayerStatus.STOPPED;
- if (AppConfig.DEBUG) Log.d(TAG, "Service created.");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Service created.");
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
manager = FeedManager.getInstance();
player = new MediaPlayer();
@@ -133,7 +135,8 @@ public class PlaybackService extends Service {
super.onDestroy();
isRunning = false;
unregisterReceiver(headsetDisconnected);
- if (AppConfig.DEBUG) Log.d(TAG, "Service is about to be destroyed");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Service is about to be destroyed");
audioManager.unregisterMediaButtonEventReceiver(mediaButtonReceiver);
audioManager.abandonAudioFocus(audioFocusChangeListener);
player.release();
@@ -152,24 +155,28 @@ public class PlaybackService extends Service {
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_LOSS:
- if (AppConfig.DEBUG) Log.d(TAG, "Lost audio focus");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Lost audio focus");
pause(true);
stopSelf();
break;
case AudioManager.AUDIOFOCUS_GAIN:
- if (AppConfig.DEBUG) Log.d(TAG, "Gained audio focus");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Gained audio focus");
if (pausedBecauseOfTransientAudiofocusLoss) {
play();
}
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
- if (AppConfig.DEBUG) Log.d(TAG, "Lost audio focus temporarily. Ducking...");
+ if (AppConfig.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:
- if (AppConfig.DEBUG) Log.d(TAG, "Lost audio focus temporarily. Pausing...");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Lost audio focus temporarily. Pausing...");
pause(false);
pausedBecauseOfTransientAudiofocusLoss = true;
}
@@ -180,7 +187,8 @@ 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) {
- if (AppConfig.DEBUG) Log.d(TAG, "Received media button event");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Received media button event");
handleKeycode(keycode);
} else {
@@ -257,7 +265,8 @@ public class PlaybackService extends Service {
* mediaplayer.
*/
public void setVideoSurface(SurfaceHolder sh) {
- if (AppConfig.DEBUG) Log.d(TAG, "Setting display");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Setting display");
player.setDisplay(null);
player.setDisplay(sh);
if (status == PlayerStatus.STOPPED
@@ -360,7 +369,8 @@ public class PlaybackService extends Service {
private MediaPlayer.OnPreparedListener preparedListener = new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
- if (AppConfig.DEBUG) Log.d(TAG, "Resource prepared");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Resource prepared");
mp.seekTo(media.getPosition());
setStatus(PlayerStatus.PREPARED);
if (startWhenPrepared) {
@@ -399,7 +409,8 @@ public class PlaybackService extends Service {
@Override
public void onCompletion(MediaPlayer mp) {
- if (AppConfig.DEBUG) Log.d(TAG, "Playback completed");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Playback completed");
// Save state
positionSaver.cancel(true);
media.setPosition(0);
@@ -416,14 +427,16 @@ public class PlaybackService extends Service {
.getBoolean(PodcastApp.PREF_FOLLOW_QUEUE, false);
FeedItem nextItem = manager.getFirstQueueItem();
if (isInQueue && followQueue && nextItem != null) {
- if (AppConfig.DEBUG) Log.d(TAG, "Loading next item in queue");
+ if (AppConfig.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 {
- if (AppConfig.DEBUG) Log.d(TAG, "Stopping playback");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Stopping playback");
stopWidgetUpdater();
setStatus(PlayerStatus.STOPPED);
stopForeground(true);
@@ -449,7 +462,8 @@ public class PlaybackService extends Service {
*/
public void pause(boolean abandonFocus) {
if (player.isPlaying()) {
- if (AppConfig.DEBUG) Log.d(TAG, "Pausing playback.");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Pausing playback.");
player.pause();
if (abandonFocus) {
audioManager.abandonAudioFocus(audioFocusChangeListener);
@@ -478,8 +492,10 @@ public class PlaybackService extends Service {
AudioManager.AUDIOFOCUS_GAIN);
if (focusGained == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
- if (AppConfig.DEBUG) Log.d(TAG, "Audiofocus successfully requested");
- if (AppConfig.DEBUG) Log.d(TAG, "Resuming/Starting playback");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Audiofocus successfully requested");
+ if (AppConfig.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());
@@ -495,13 +511,15 @@ public class PlaybackService extends Service {
setupNotification();
pausedBecauseOfTransientAudiofocusLoss = false;
} else {
- if (AppConfig.DEBUG) Log.d(TAG, "Failed to request Audiofocus");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Failed to request Audiofocus");
}
}
}
private void setStatus(PlayerStatus newStatus) {
- if (AppConfig.DEBUG) Log.d(TAG, "Setting status to " + newStatus);
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Setting status to " + newStatus);
status = newStatus;
sendBroadcast(new Intent(ACTION_PLAYER_STATUS_CHANGED));
updateWidget();
@@ -529,7 +547,8 @@ public class PlaybackService extends Service {
.setSmallIcon(R.drawable.ic_stat_antenna);
startForeground(NOTIFICATION_ID, notificationBuilder.getNotification());
- if (AppConfig.DEBUG) Log.d(TAG, "Notification set up");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Notification set up");
}
/**
@@ -543,7 +562,8 @@ public class PlaybackService extends Service {
}
public void seek(int i) {
- if (AppConfig.DEBUG) Log.d(TAG, "Seeking position " + i);
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Seeking position " + i);
if (shouldStream) {
statusBeforeSeek = status;
setStatus(PlayerStatus.SEEKING);
@@ -552,9 +572,15 @@ public class PlaybackService extends Service {
saveCurrentPosition();
}
+ public void seekToChapter(SimpleChapter chapter) {
+ seek((int) chapter.getStart());
+ }
+
/** Saves the current position of the media file to the DB */
private synchronized void saveCurrentPosition() {
- if (AppConfig.DEBUG) Log.d(TAG, "Saving current position to " + player.getCurrentPosition());
+ if (AppConfig.DEBUG)
+ Log.d(TAG,
+ "Saving current position to " + player.getCurrentPosition());
media.setPosition(player.getCurrentPosition());
manager.setFeedMedia(this, media);
}
@@ -577,7 +603,8 @@ public class PlaybackService extends Service {
}
private void updateWidget() {
- if (AppConfig.DEBUG) Log.d(TAG, "Sending widget update request");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Sending widget update request");
PlaybackService.this.sendBroadcast(new Intent(
PlayerWidget.FORCE_WIDGET_UPDATE));
}
@@ -595,19 +622,22 @@ public class PlaybackService extends Service {
if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
int state = intent.getIntExtra("state", -1);
if (state != -1) {
- if (AppConfig.DEBUG) Log.d(TAG, "Headset plug event. State is " + state);
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Headset plug event. State is " + state);
boolean pauseOnDisconnect = PreferenceManager
.getDefaultSharedPreferences(
getApplicationContext())
.getBoolean(
PodcastApp.PREF_PAUSE_ON_HEADSET_DISCONNECT,
false);
- if (AppConfig.DEBUG) Log.d(TAG, "pauseOnDisconnect preference is "
- + pauseOnDisconnect);
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "pauseOnDisconnect preference is "
+ + pauseOnDisconnect);
if (state == UNPLUGGED && pauseOnDisconnect
&& status == PlayerStatus.PLAYING) {
- if (AppConfig.DEBUG) Log.d(TAG,
- "Pausing playback because headset was disconnected");
+ if (AppConfig.DEBUG)
+ Log.d(TAG,
+ "Pausing playback because headset was disconnected");
pause(true);
}
} else {
@@ -628,11 +658,13 @@ public class PlaybackService extends Service {
Thread.sleep(WAITING_INTERVALL);
saveCurrentPosition();
} catch (InterruptedException e) {
- if (AppConfig.DEBUG) Log.d(TAG,
- "Thread was interrupted while waiting. Finishing now...");
+ if (AppConfig.DEBUG)
+ Log.d(TAG,
+ "Thread was interrupted while waiting. Finishing now...");
return null;
} catch (IllegalStateException e) {
- if (AppConfig.DEBUG) Log.d(TAG, "Player is in illegal state. Finishing now");
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Player is in illegal state. Finishing now");
return null;
}
diff --git a/src/de/danoeh/antennapod/storage/PodDBAdapter.java b/src/de/danoeh/antennapod/storage/PodDBAdapter.java
index 1389f6955..4c208f187 100644
--- a/src/de/danoeh/antennapod/storage/PodDBAdapter.java
+++ b/src/de/danoeh/antennapod/storage/PodDBAdapter.java
@@ -507,7 +507,7 @@ public class PodDBAdapter {
public final Cursor getSimpleChaptersOfFeedItemCursor(final FeedItem item) {
open();
Cursor c = db
- .query(TABLE_NAME_SIMPLECHAPTERS, null, KEY_ID + "=?",
+ .query(TABLE_NAME_SIMPLECHAPTERS, null, KEY_FEEDITEM + "=?",
new String[] { String.valueOf(item.getId()) }, null,
null, null);
return c;