Search in sources :

Example 26 with FeedMedia

use of de.danoeh.antennapod.core.feed.FeedMedia in project AntennaPod by AntennaPod.

the class UITestUtils method addHostedFeedData.

/**
     * Adds feeds, images and episodes to the webserver for testing purposes.
     */
public void addHostedFeedData() throws IOException {
    if (feedDataHosted)
        throw new IllegalStateException("addHostedFeedData was called twice on the same instance");
    for (int i = 0; i < NUM_FEEDS; i++) {
        File bitmapFile = newBitmapFile("image" + i);
        FeedImage image = new FeedImage(0, "image " + i, null, hostFile(bitmapFile), false);
        Feed feed = new Feed(0, null, "Title " + i, "http://example.com/" + i, "Description of feed " + i, "http://example.com/pay/feed" + i, "author " + i, "en", Feed.TYPE_RSS2, "feed" + i, image, null, "http://example.com/feed/src/" + i, false);
        image.setOwner(feed);
        // create items
        List<FeedItem> items = new ArrayList<FeedItem>();
        for (int j = 0; j < NUM_ITEMS_PER_FEED; j++) {
            FeedItem item = new FeedItem(j, "Feed " + (i + 1) + ": Item " + (j + 1), "item" + j, "http://example.com/feed" + i + "/item/" + j, new Date(), FeedItem.UNPLAYED, feed);
            items.add(item);
            File mediaFile = newMediaFile("feed-" + i + "-episode-" + j + ".mp3");
            item.setMedia(new FeedMedia(j, item, 0, 0, mediaFile.length(), "audio/mp3", null, hostFile(mediaFile), false, null, 0, 0));
        }
        feed.setItems(items);
        feed.setDownload_url(hostFeed(feed));
        hostedFeeds.add(feed);
    }
    feedDataHosted = true;
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ArrayList(java.util.ArrayList) File(java.io.File) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 27 with FeedMedia

use of de.danoeh.antennapod.core.feed.FeedMedia in project AntennaPod by AntennaPod.

the class UITestUtils method addLocalFeedData.

/**
     * Adds feeds, images and episodes to the local database. This method will also call addHostedFeedData if it has not
     * been called yet.
     *
     * Adds one item of each feed to the queue and to the playback history.
     *
     * This method should NOT be called if the testing class wants to download the hosted feed data.
     *
     * @param downloadEpisodes true if episodes should also be marked as downloaded.
     */
public void addLocalFeedData(boolean downloadEpisodes) throws Exception {
    if (localFeedDataAdded) {
        Log.w(TAG, "addLocalFeedData was called twice on the same instance");
        // might be a flaky test, this is actually not that severe
        return;
    }
    if (!feedDataHosted) {
        addHostedFeedData();
    }
    List<FeedItem> queue = new ArrayList<>();
    for (Feed feed : hostedFeeds) {
        feed.setDownloaded(true);
        if (feed.getImage() != null) {
            FeedImage image = feed.getImage();
            int fileId = Integer.parseInt(StringUtils.substringAfter(image.getDownload_url(), "files/"));
            image.setFile_url(server.accessFile(fileId).getAbsolutePath());
            image.setDownloaded(true);
        }
        if (downloadEpisodes) {
            for (FeedItem item : feed.getItems()) {
                if (item.hasMedia()) {
                    FeedMedia media = item.getMedia();
                    int fileId = Integer.parseInt(StringUtils.substringAfter(media.getDownload_url(), "files/"));
                    media.setFile_url(server.accessFile(fileId).getAbsolutePath());
                    media.setDownloaded(true);
                }
            }
        }
        queue.add(feed.getItems().get(0));
        feed.getItems().get(1).getMedia().setPlaybackCompletionDate(new Date());
    }
    localFeedDataAdded = true;
    PodDBAdapter adapter = PodDBAdapter.getInstance();
    adapter.open();
    adapter.setCompleteFeed(hostedFeeds.toArray(new Feed[hostedFeeds.size()]));
    adapter.setQueue(queue);
    adapter.close();
    EventDistributor.getInstance().sendFeedUpdateBroadcast();
    EventBus.getDefault().post(QueueEvent.setQueue(queue));
}
Also used : PodDBAdapter(de.danoeh.antennapod.core.storage.PodDBAdapter) FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ArrayList(java.util.ArrayList) Date(java.util.Date) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 28 with FeedMedia

use of de.danoeh.antennapod.core.feed.FeedMedia in project AntennaPod by AntennaPod.

the class PlaybackService method getNextInQueue.

private Playable getNextInQueue(final Playable currentMedia) {
    if (!(currentMedia instanceof FeedMedia)) {
        Log.d(TAG, "getNextInQueue(), but playable not an instance of FeedMedia, so not proceeding");
        return null;
    }
    if (!ClientConfig.playbackServiceCallbacks.useQueue()) {
        Log.d(TAG, "getNextInQueue(), but queue not in use by this app");
        return null;
    }
    Log.d(TAG, "getNextInQueue()");
    FeedMedia media = (FeedMedia) currentMedia;
    try {
        media.loadMetadata();
    } catch (Playable.PlayableException e) {
        Log.e(TAG, "Unable to load metadata to get next in queue", e);
        return null;
    }
    FeedItem item = media.getItem();
    if (item == null) {
        Log.w(TAG, "getNextInQueue() with FeedMedia object whose FeedItem is null");
        return null;
    }
    FeedItem nextItem;
    try {
        final List<FeedItem> queue = taskManager.getQueue();
        nextItem = DBTasks.getQueueSuccessorOfItem(item.getId(), queue);
    } catch (InterruptedException e) {
        Log.e(TAG, "Error handling the queue in order to retrieve the next item", e);
        return null;
    }
    return (nextItem != null) ? nextItem.getMedia() : null;
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) Playable(de.danoeh.antennapod.core.util.playback.Playable)

Example 29 with FeedMedia

use of de.danoeh.antennapod.core.feed.FeedMedia in project AntennaPod by AntennaPod.

the class PlaybackService method onPostPlayback.

/**
     * This method processes the media object after its playback ended, either because it completed
     * or because a different media object was selected for playback.
     *
     * Even though these tasks aren't supposed to be resource intensive, a good practice is to
     * usually call this method on a background thread.
     *
     * @param playable    the media object that was playing. It is assumed that its position
     *                    property was updated before this method was called.
     * @param ended       if true, it signals that {@param playable} was played until its end.
     *                    In such case, the position property of the media becomes irrelevant for
     *                    most of the tasks (although it's still a good practice to keep it
     *                    accurate).
     * @param skipped     if the user pressed a skip >| button.
     * @param playingNext if true, it means another media object is being loaded in place of this
     *                    one.
     *                    Instances when we'd set it to false would be when we're not following the
     *                    queue or when the queue has ended.
     */
private void onPostPlayback(final Playable playable, boolean ended, boolean skipped, boolean playingNext) {
    if (playable == null) {
        Log.e(TAG, "Cannot do post-playback processing: media was null");
        return;
    }
    Log.d(TAG, "onPostPlayback(): media=" + playable.getEpisodeTitle());
    if (!(playable instanceof FeedMedia)) {
        Log.d(TAG, "Not doing post-playback processing: media not of type FeedMedia");
        if (ended) {
            playable.onPlaybackCompleted(getApplicationContext());
        } else {
            playable.onPlaybackPause(getApplicationContext());
        }
        return;
    }
    FeedMedia media = (FeedMedia) playable;
    FeedItem item = media.getItem();
    boolean smartMarkAsPlayed = playingNext && media.hasAlmostEnded();
    if (!ended && smartMarkAsPlayed) {
        Log.d(TAG, "smart mark as played");
    }
    if (ended || smartMarkAsPlayed) {
        media.onPlaybackCompleted(getApplicationContext());
    } else {
        media.onPlaybackPause(getApplicationContext());
    }
    if (item != null) {
        if (ended || smartMarkAsPlayed || (skipped && !UserPreferences.shouldSkipKeepEpisode())) {
            // only mark the item as played if we're not keeping it anyways
            DBWriter.markItemPlayed(item, FeedItem.PLAYED, ended);
            try {
                final List<FeedItem> queue = taskManager.getQueue();
                if (QueueAccess.ItemListAccess(queue).contains(item.getId())) {
                    // don't know if it actually matters to not autodownload when smart mark as played is triggered
                    DBWriter.removeQueueItem(PlaybackService.this, item, ended);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            // isInQueue remains false
            }
            // Delete episode if enabled
            if (item.getFeed().getPreferences().getCurrentAutoDelete()) {
                DBWriter.deleteFeedMediaOfItem(PlaybackService.this, media.getId());
                Log.d(TAG, "Episode Deleted");
            }
        }
    }
    if (ended || skipped || playingNext) {
        DBWriter.addItemToPlaybackHistory(media);
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia)

Example 30 with FeedMedia

use of de.danoeh.antennapod.core.feed.FeedMedia in project AntennaPod by AntennaPod.

the class PlaybackService method writePlaybackPreferences.

private void writePlaybackPreferences() {
    Log.d(TAG, "Writing playback preferences");
    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
    PlaybackServiceMediaPlayer.PSMPInfo info = mediaPlayer.getPSMPInfo();
    MediaType mediaType = mediaPlayer.getCurrentMediaType();
    boolean stream = mediaPlayer.isStreaming();
    int playerStatus = getCurrentPlayerStatusAsInt(info.playerStatus);
    if (info.playable != null) {
        editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_MEDIA, info.playable.getPlayableType());
        editor.putBoolean(PlaybackPreferences.PREF_CURRENT_EPISODE_IS_STREAM, stream);
        editor.putBoolean(PlaybackPreferences.PREF_CURRENT_EPISODE_IS_VIDEO, mediaType == MediaType.VIDEO);
        if (info.playable instanceof FeedMedia) {
            FeedMedia fMedia = (FeedMedia) info.playable;
            editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID, fMedia.getItem().getFeed().getId());
            editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, fMedia.getId());
        } else {
            editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID, PlaybackPreferences.NO_MEDIA_PLAYING);
            editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, PlaybackPreferences.NO_MEDIA_PLAYING);
        }
        info.playable.writeToPreferences(editor);
    } else {
        editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_MEDIA, PlaybackPreferences.NO_MEDIA_PLAYING);
        editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID, PlaybackPreferences.NO_MEDIA_PLAYING);
        editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, PlaybackPreferences.NO_MEDIA_PLAYING);
    }
    editor.putInt(PlaybackPreferences.PREF_CURRENT_PLAYER_STATUS, playerStatus);
    editor.commit();
}
Also used : SharedPreferences(android.content.SharedPreferences) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) MediaType(de.danoeh.antennapod.core.feed.MediaType)

Aggregations

FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)53 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)39 Feed (de.danoeh.antennapod.core.feed.Feed)20 Date (java.util.Date)19 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)16 ArrayList (java.util.ArrayList)13 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)10 File (java.io.File)9 Intent (android.content.Intent)7 Playable (de.danoeh.antennapod.core.util.playback.Playable)7 Cursor (android.database.Cursor)6 SharedPreferences (android.content.SharedPreferences)4 TypedArray (android.content.res.TypedArray)3 Uri (android.net.Uri)3 View (android.view.View)3 Chapter (de.danoeh.antennapod.core.feed.Chapter)3 GpodnetEpisodeAction (de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction)3 Context (android.content.Context)2 ArrayMap (android.support.v4.util.ArrayMap)2 FlakyTest (android.test.FlakyTest)2