Fixed error message when file was deleted
This commit is contained in:
parent
03d1f41e9b
commit
a9d93c9074
|
@ -8,6 +8,7 @@ import androidx.annotation.Nullable;
|
|||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
|
||||
import de.test.antennapod.EspressoTestUtils;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.awaitility.core.ConditionTimeoutException;
|
||||
|
@ -113,7 +114,11 @@ public class AutoDownloadTest {
|
|||
|
||||
private void playEpisode(@NonNull FeedItem item) {
|
||||
FeedMedia media = item.getMedia();
|
||||
DBTasks.playMedia(context, media, false, true, true);
|
||||
new PlaybackServiceStarter(context, media)
|
||||
.callEvenIfRunning(true)
|
||||
.startWhenPrepared(true)
|
||||
.shouldStream(true)
|
||||
.start();
|
||||
Awaitility.await("episode is playing")
|
||||
.atMost(2000, MILLISECONDS)
|
||||
.until(() -> item.equals(getCurrentlyPlaying()));
|
||||
|
|
|
@ -6,6 +6,7 @@ import androidx.annotation.StringRes;
|
|||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
|
||||
|
||||
public class PlayActionButton extends ItemActionButton {
|
||||
|
@ -32,7 +33,10 @@ public class PlayActionButton extends ItemActionButton {
|
|||
if (media == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!media.fileExists()) {
|
||||
DBTasks.notifyMissingFeedMediaFile(context, media);
|
||||
return;
|
||||
}
|
||||
new PlaybackServiceStarter(context, media)
|
||||
.callEvenIfRunning(true)
|
||||
.startWhenPrepared(true)
|
||||
|
|
|
@ -8,14 +8,10 @@ import androidx.annotation.StringRes;
|
|||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||
import de.danoeh.antennapod.core.util.IntentUtils;
|
||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
|
||||
import de.danoeh.antennapod.dialog.StreamingConfirmationDialog;
|
||||
|
||||
import static de.danoeh.antennapod.core.service.playback.PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE;
|
||||
|
||||
public class StreamActionButton extends ItemActionButton {
|
||||
|
||||
public StreamActionButton(FeedItem item) {
|
||||
|
@ -44,6 +40,10 @@ public class StreamActionButton extends ItemActionButton {
|
|||
new StreamingConfirmationDialog(context, media).show();
|
||||
return;
|
||||
}
|
||||
DBTasks.playMedia(context, media, false, true, true);
|
||||
new PlaybackServiceStarter(context, media)
|
||||
.callEvenIfRunning(true)
|
||||
.startWhenPrepared(true)
|
||||
.shouldStream(true)
|
||||
.start();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,12 +30,16 @@ public class FeedItemEvent {
|
|||
return new FeedItemEvent(Action.DELETE_MEDIA, items);
|
||||
}
|
||||
|
||||
public static FeedItemEvent deletedMedia(FeedItem... items) {
|
||||
return deletedMedia(Arrays.asList(items));
|
||||
}
|
||||
|
||||
public static FeedItemEvent updated(List<FeedItem> items) {
|
||||
return new FeedItemEvent(Action.UPDATE, items);
|
||||
}
|
||||
|
||||
public static FeedItemEvent updated(FeedItem... items) {
|
||||
return new FeedItemEvent(Action.UPDATE, Arrays.asList(items));
|
||||
return updated(Arrays.asList(items));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,9 +6,22 @@ import android.database.Cursor;
|
|||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import de.danoeh.antennapod.core.ClientConfig;
|
||||
import de.danoeh.antennapod.core.R;
|
||||
import de.danoeh.antennapod.core.event.FeedItemEvent;
|
||||
import de.danoeh.antennapod.core.event.FeedListUpdateEvent;
|
||||
import de.danoeh.antennapod.core.event.MessageEvent;
|
||||
import de.danoeh.antennapod.core.feed.Feed;
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.feed.FeedPreferences;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.service.GpodnetSyncService;
|
||||
import de.danoeh.antennapod.core.service.download.DownloadStatus;
|
||||
import de.danoeh.antennapod.core.util.DownloadError;
|
||||
import de.danoeh.antennapod.core.util.LongList;
|
||||
import de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -24,23 +37,6 @@ import java.util.concurrent.Future;
|
|||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import de.danoeh.antennapod.core.ClientConfig;
|
||||
import de.danoeh.antennapod.core.event.FeedListUpdateEvent;
|
||||
import de.danoeh.antennapod.core.feed.Feed;
|
||||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.feed.FeedPreferences;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.service.GpodnetSyncService;
|
||||
import de.danoeh.antennapod.core.service.download.DownloadStatus;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||
import de.danoeh.antennapod.core.util.DownloadError;
|
||||
import de.danoeh.antennapod.core.util.IntentUtils;
|
||||
import de.danoeh.antennapod.core.util.LongList;
|
||||
import de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator;
|
||||
import de.danoeh.antennapod.core.util.exception.MediaFileNotFoundException;
|
||||
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
/**
|
||||
|
@ -100,53 +96,6 @@ public final class DBTasks {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts playback of a FeedMedia object's file. This method will build an Intent based on the given parameters to
|
||||
* start the {@link PlaybackService}.
|
||||
*
|
||||
* @param context Used for sending starting Services and Activities.
|
||||
* @param media The FeedMedia object.
|
||||
* @param showPlayer If true, starts the appropriate player activity ({@link de.danoeh.antennapod.activity.AudioplayerActivity}
|
||||
* or {@link de.danoeh.antennapod.activity.VideoplayerActivity}
|
||||
* @param startWhenPrepared Parameter for the {@link PlaybackService} start intent. If true, playback will start as
|
||||
* soon as the PlaybackService has finished loading the FeedMedia object's file.
|
||||
* @param shouldStream Parameter for the {@link PlaybackService} start intent. If true, the FeedMedia object's file
|
||||
* will be streamed, otherwise the downloaded file will be used. If the downloaded file cannot be
|
||||
* found, the PlaybackService will shutdown and the database entry of the FeedMedia object will be
|
||||
* corrected.
|
||||
*/
|
||||
public static void playMedia(final Context context, final FeedMedia media,
|
||||
boolean showPlayer, boolean startWhenPrepared, boolean shouldStream) {
|
||||
try {
|
||||
if (!shouldStream) {
|
||||
if (!media.fileExists()) {
|
||||
throw new MediaFileNotFoundException(
|
||||
"No episode was found at " + media.getFile_url(),
|
||||
media);
|
||||
}
|
||||
}
|
||||
|
||||
new PlaybackServiceStarter(context, media)
|
||||
.callEvenIfRunning(true)
|
||||
.startWhenPrepared(startWhenPrepared)
|
||||
.shouldStream(shouldStream)
|
||||
.start();
|
||||
|
||||
if (showPlayer) {
|
||||
// Launch media player
|
||||
context.startActivity(PlaybackService.getPlayerActivityIntent(
|
||||
context, media));
|
||||
}
|
||||
DBWriter.addQueueItemAt(context, media.getItem().getId(), 0, false);
|
||||
} catch (MediaFileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
if (media.isPlaying()) {
|
||||
IntentUtils.sendLocalBroadcast(context, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
|
||||
}
|
||||
notifyMissingFeedMediaFile(context, media);
|
||||
}
|
||||
}
|
||||
|
||||
private static final AtomicBoolean isRefreshing = new AtomicBoolean(false);
|
||||
|
||||
/**
|
||||
|
@ -293,17 +242,16 @@ public final class DBTasks {
|
|||
}
|
||||
|
||||
/**
|
||||
* Notifies the database about a missing FeedMedia file. This method will correct the FeedMedia object's values in the
|
||||
* DB and send a FeedUpdateBroadcast.
|
||||
* Notifies the database about a missing FeedMedia file. This method will correct the FeedMedia object's
|
||||
* values in the DB and send a FeedItemEvent.
|
||||
*/
|
||||
public static void notifyMissingFeedMediaFile(final Context context,
|
||||
final FeedMedia media) {
|
||||
Log.i(TAG,
|
||||
"The feedmanager was notified about a missing episode. It will update its database now.");
|
||||
public static void notifyMissingFeedMediaFile(final Context context, final FeedMedia media) {
|
||||
Log.i(TAG, "The feedmanager was notified about a missing episode. It will update its database now.");
|
||||
media.setDownloaded(false);
|
||||
media.setFile_url(null);
|
||||
DBWriter.setFeedMedia(media);
|
||||
EventBus.getDefault().post(new FeedListUpdateEvent(media.getItem().getFeed()));
|
||||
EventBus.getDefault().post(FeedItemEvent.deletedMedia(media.getItem()));
|
||||
EventBus.getDefault().post(new MessageEvent(context.getString(R.string.error_file_not_found)));
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
|
||||
|
|
|
@ -289,6 +289,7 @@
|
|||
<string name="player_buffering_msg">Buffering</string>
|
||||
<string name="player_go_to_picture_in_picture">Picture-in-picture mode</string>
|
||||
<string name="unknown_media_key">AntennaPod - Unknown media key: %1$d</string>
|
||||
<string name="error_file_not_found">File not found</string>
|
||||
|
||||
<!-- Queue operations -->
|
||||
<string name="lock_queue">Lock Queue</string>
|
||||
|
|
Loading…
Reference in New Issue