PlaybackController now checks if episode exists when the restoring last
played episode.
This commit is contained in:
parent
7d44a549bc
commit
1d8107827c
|
@ -1,5 +1,7 @@
|
||||||
package de.danoeh.antennapod.feed;
|
package de.danoeh.antennapod.feed;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/** Represents a component of a Feed that has to be downloaded */
|
/** Represents a component of a Feed that has to be downloaded */
|
||||||
public abstract class FeedFile extends FeedComponent {
|
public abstract class FeedFile extends FeedComponent {
|
||||||
|
|
||||||
|
@ -53,6 +55,16 @@ public abstract class FeedFile extends FeedComponent {
|
||||||
return false;
|
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() {
|
public String getFile_url() {
|
||||||
return file_url;
|
return file_url;
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,19 +124,12 @@ public class FeedManager {
|
||||||
boolean startWhenPrepared, boolean shouldStream) {
|
boolean startWhenPrepared, boolean shouldStream) {
|
||||||
try {
|
try {
|
||||||
if (!shouldStream) {
|
if (!shouldStream) {
|
||||||
if (media.getFile_url() == null) {
|
if (media.fileExists() == false) {
|
||||||
throw new MediaFileNotFoundException("Feed URL was null",
|
|
||||||
media);
|
|
||||||
} else {
|
|
||||||
File f = new File(media.getFile_url());
|
|
||||||
if (!f.exists() || !f.canRead()) {
|
|
||||||
throw new MediaFileNotFoundException(
|
throw new MediaFileNotFoundException(
|
||||||
"No episode was found at "
|
"No episode was found at " + media.getFile_url(),
|
||||||
+ media.getFile_url(), media);
|
media);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
// Start playback Service
|
// Start playback Service
|
||||||
Intent launchIntent = new Intent(context, PlaybackService.class);
|
Intent launchIntent = new Intent(context, PlaybackService.class);
|
||||||
launchIntent
|
launchIntent
|
||||||
|
|
|
@ -28,6 +28,7 @@ import android.widget.TextView;
|
||||||
import de.danoeh.antennapod.AppConfig;
|
import de.danoeh.antennapod.AppConfig;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.feed.Chapter;
|
import de.danoeh.antennapod.feed.Chapter;
|
||||||
|
import de.danoeh.antennapod.feed.FeedManager;
|
||||||
import de.danoeh.antennapod.feed.FeedMedia;
|
import de.danoeh.antennapod.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.service.PlaybackService;
|
import de.danoeh.antennapod.service.PlaybackService;
|
||||||
import de.danoeh.antennapod.service.PlayerStatus;
|
import de.danoeh.antennapod.service.PlayerStatus;
|
||||||
|
@ -188,24 +189,32 @@ public abstract class PlaybackController {
|
||||||
long feedId = prefs.getLong(PlaybackService.PREF_LAST_PLAYED_FEED_ID,
|
long feedId = prefs.getLong(PlaybackService.PREF_LAST_PLAYED_FEED_ID,
|
||||||
-1);
|
-1);
|
||||||
if (mediaId != -1 && feedId != -1) {
|
if (mediaId != -1 && feedId != -1) {
|
||||||
Intent serviceIntent = new Intent(activity, PlaybackService.class);
|
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_FEED_ID, feedId);
|
||||||
serviceIntent.putExtra(PlaybackService.EXTRA_MEDIA_ID, mediaId);
|
serviceIntent.putExtra(PlaybackService.EXTRA_MEDIA_ID, mediaId);
|
||||||
serviceIntent.putExtra(PlaybackService.EXTRA_START_WHEN_PREPARED,
|
serviceIntent.putExtra(
|
||||||
false);
|
PlaybackService.EXTRA_START_WHEN_PREPARED, false);
|
||||||
serviceIntent.putExtra(PlaybackService.EXTRA_PREPARE_IMMEDIATELY,
|
serviceIntent.putExtra(
|
||||||
false);
|
PlaybackService.EXTRA_PREPARE_IMMEDIATELY, false);
|
||||||
serviceIntent
|
boolean fileExists = media.fileExists();
|
||||||
.putExtra(PlaybackService.EXTRA_SHOULD_STREAM, prefs
|
boolean lastIsStream = prefs.getBoolean(
|
||||||
.getBoolean(PlaybackService.PREF_LAST_IS_STREAM,
|
PlaybackService.PREF_LAST_IS_STREAM, true);
|
||||||
true));
|
if (!fileExists && !lastIsStream) {
|
||||||
|
FeedManager.getInstance().notifyMissingFeedMediaFile(
|
||||||
|
activity, media);
|
||||||
|
}
|
||||||
|
serviceIntent.putExtra(PlaybackService.EXTRA_SHOULD_STREAM,
|
||||||
|
lastIsStream || !fileExists);
|
||||||
return serviceIntent;
|
return serviceIntent;
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "No last played media found");
|
Log.d(TAG, "No last played media found");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void setupGUI();
|
public abstract void setupGUI();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue