diff --git a/src/de/danoeh/antennapod/feed/FeedFile.java b/src/de/danoeh/antennapod/feed/FeedFile.java index 305d58c1b..1d7a135d4 100644 --- a/src/de/danoeh/antennapod/feed/FeedFile.java +++ b/src/de/danoeh/antennapod/feed/FeedFile.java @@ -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; diff --git a/src/de/danoeh/antennapod/feed/FeedManager.java b/src/de/danoeh/antennapod/feed/FeedManager.java index 597936e5a..3e5e838b0 100644 --- a/src/de/danoeh/antennapod/feed/FeedManager.java +++ b/src/de/danoeh/antennapod/feed/FeedManager.java @@ -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); diff --git a/src/de/danoeh/antennapod/util/PlaybackController.java b/src/de/danoeh/antennapod/util/PlaybackController.java index 7d732f042..1a61555ff 100644 --- a/src/de/danoeh/antennapod/util/PlaybackController.java +++ b/src/de/danoeh/antennapod/util/PlaybackController.java @@ -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();