PlaybackController now checks if episode exists when the restoring last

played episode.
This commit is contained in:
daniel oeh 2013-01-13 22:48:58 +01:00
parent 7d44a549bc
commit 1d8107827c
3 changed files with 40 additions and 26 deletions

View File

@ -1,5 +1,7 @@
package de.danoeh.antennapod.feed;
import java.io.File;
/** Represents a component of a Feed that has to be downloaded */
public abstract class FeedFile extends FeedComponent {
@ -52,6 +54,16 @@ public abstract class FeedFile extends FeedComponent {
}
return false;
}
/** Returns true if the file exists at file_url. */
public boolean fileExists() {
if (file_url == null) {
return false;
} else {
File f = new File(file_url);
return f.exists();
}
}
public String getFile_url() {
return file_url;

View File

@ -124,18 +124,11 @@ public class FeedManager {
boolean startWhenPrepared, boolean shouldStream) {
try {
if (!shouldStream) {
if (media.getFile_url() == null) {
throw new MediaFileNotFoundException("Feed URL was null",
if (media.fileExists() == false) {
throw new MediaFileNotFoundException(
"No episode was found at " + media.getFile_url(),
media);
} else {
File f = new File(media.getFile_url());
if (!f.exists() || !f.canRead()) {
throw new MediaFileNotFoundException(
"No episode was found at "
+ media.getFile_url(), media);
}
}
}
// Start playback Service
Intent launchIntent = new Intent(context, PlaybackService.class);

View File

@ -28,6 +28,7 @@ import android.widget.TextView;
import de.danoeh.antennapod.AppConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.feed.Chapter;
import de.danoeh.antennapod.feed.FeedManager;
import de.danoeh.antennapod.feed.FeedMedia;
import de.danoeh.antennapod.service.PlaybackService;
import de.danoeh.antennapod.service.PlayerStatus;
@ -188,23 +189,31 @@ public abstract class PlaybackController {
long feedId = prefs.getLong(PlaybackService.PREF_LAST_PLAYED_FEED_ID,
-1);
if (mediaId != -1 && feedId != -1) {
Intent serviceIntent = new Intent(activity, PlaybackService.class);
serviceIntent.putExtra(PlaybackService.EXTRA_FEED_ID, feedId);
serviceIntent.putExtra(PlaybackService.EXTRA_MEDIA_ID, mediaId);
serviceIntent.putExtra(PlaybackService.EXTRA_START_WHEN_PREPARED,
false);
serviceIntent.putExtra(PlaybackService.EXTRA_PREPARE_IMMEDIATELY,
false);
serviceIntent
.putExtra(PlaybackService.EXTRA_SHOULD_STREAM, prefs
.getBoolean(PlaybackService.PREF_LAST_IS_STREAM,
true));
return serviceIntent;
} else {
if (AppConfig.DEBUG)
Log.d(TAG, "No last played media found");
return null;
FeedMedia media = FeedManager.getInstance().getFeedMedia(mediaId);
if (media != null) {
Intent serviceIntent = new Intent(activity,
PlaybackService.class);
serviceIntent.putExtra(PlaybackService.EXTRA_FEED_ID, feedId);
serviceIntent.putExtra(PlaybackService.EXTRA_MEDIA_ID, mediaId);
serviceIntent.putExtra(
PlaybackService.EXTRA_START_WHEN_PREPARED, false);
serviceIntent.putExtra(
PlaybackService.EXTRA_PREPARE_IMMEDIATELY, false);
boolean fileExists = media.fileExists();
boolean lastIsStream = prefs.getBoolean(
PlaybackService.PREF_LAST_IS_STREAM, true);
if (!fileExists && !lastIsStream) {
FeedManager.getInstance().notifyMissingFeedMediaFile(
activity, media);
}
serviceIntent.putExtra(PlaybackService.EXTRA_SHOULD_STREAM,
lastIsStream || !fileExists);
return serviceIntent;
}
}
if (AppConfig.DEBUG)
Log.d(TAG, "No last played media found");
return null;
}
public abstract void setupGUI();