Search in sources :

Example 61 with FeedItem

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

the class UITestUtilsTest method testAddHostedFeeds.

public void testAddHostedFeeds() throws Exception {
    uiTestUtils.addHostedFeedData();
    final List<Feed> feeds = uiTestUtils.hostedFeeds;
    assertNotNull(feeds);
    assertFalse(feeds.isEmpty());
    for (Feed feed : feeds) {
        testUrlReachable(feed.getDownload_url());
        if (feed.getImage() != null) {
            testUrlReachable(feed.getImage().getDownload_url());
        }
        for (FeedItem item : feed.getItems()) {
            if (item.hasMedia()) {
                testUrlReachable(item.getMedia().getDownload_url());
            }
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Feed(de.danoeh.antennapod.core.feed.Feed)

Example 62 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem 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 63 with FeedItem

use of de.danoeh.antennapod.core.feed.FeedItem 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 64 with FeedItem

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

the class PlaybackService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "Service created.");
    isRunning = true;
    registerReceiver(autoStateUpdated, new IntentFilter("com.google.android.gms.car.media.STATUS"));
    registerReceiver(headsetDisconnected, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
    registerReceiver(shutdownReceiver, new IntentFilter(ACTION_SHUTDOWN_PLAYBACK_SERVICE));
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        registerReceiver(bluetoothStateUpdated, new IntentFilter(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED));
    }
    registerReceiver(audioBecomingNoisy, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
    registerReceiver(skipCurrentEpisodeReceiver, new IntentFilter(ACTION_SKIP_CURRENT_EPISODE));
    registerReceiver(pausePlayCurrentEpisodeReceiver, new IntentFilter(ACTION_PAUSE_PLAY_CURRENT_EPISODE));
    registerReceiver(pauseResumeCurrentEpisodeReceiver, new IntentFilter(ACTION_RESUME_PLAY_CURRENT_EPISODE));
    taskManager = new PlaybackServiceTaskManager(this, taskManagerCallback);
    flavorHelper = new PlaybackServiceFlavorHelper(PlaybackService.this, flavorHelperCallback);
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(prefListener);
    ComponentName eventReceiver = new ComponentName(getApplicationContext(), MediaButtonReceiver.class);
    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setComponent(eventReceiver);
    PendingIntent buttonReceiverIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    mediaSession = new MediaSessionCompat(getApplicationContext(), TAG, eventReceiver, buttonReceiverIntent);
    setSessionToken(mediaSession.getSessionToken());
    try {
        mediaSession.setCallback(sessionCallback);
        mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    } catch (NullPointerException npe) {
        // on some devices (Huawei) setting active can cause a NullPointerException
        // even with correct use of the api.
        // See http://stackoverflow.com/questions/31556679/android-huawei-mediassessioncompat
        // and https://plus.google.com/+IanLake/posts/YgdTkKFxz7d
        Log.e(TAG, "NullPointerException while setting up MediaSession");
        npe.printStackTrace();
    }
    List<MediaSessionCompat.QueueItem> queueItems = new ArrayList<>();
    try {
        for (FeedItem feedItem : taskManager.getQueue()) {
            if (feedItem.getMedia() != null) {
                MediaDescriptionCompat mediaDescription = feedItem.getMedia().getMediaItem().getDescription();
                queueItems.add(new MediaSessionCompat.QueueItem(mediaDescription, feedItem.getId()));
            }
        }
        mediaSession.setQueue(queueItems);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    flavorHelper.initializeMediaPlayer(PlaybackService.this);
    mediaSession.setActive(true);
}
Also used : IntentFilter(android.content.IntentFilter) ArrayList(java.util.ArrayList) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) MediaSessionCompat(android.support.v4.media.session.MediaSessionCompat) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) MediaDescriptionCompat(android.support.v4.media.MediaDescriptionCompat)

Example 65 with FeedItem

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

the class PlaybackService method bluetoothNotifyChange.

private void bluetoothNotifyChange(PlaybackServiceMediaPlayer.PSMPInfo info, String whatChanged) {
    boolean isPlaying = false;
    if (info.playerStatus == PlayerStatus.PLAYING) {
        isPlaying = true;
    }
    if (info.playable != null) {
        Intent i = new Intent(whatChanged);
        i.putExtra("id", 1L);
        i.putExtra("artist", "");
        i.putExtra("album", info.playable.getFeedTitle());
        i.putExtra("track", info.playable.getEpisodeTitle());
        i.putExtra("playing", isPlaying);
        final List<FeedItem> queue = taskManager.getQueueIfLoaded();
        if (queue != null) {
            i.putExtra("ListSize", queue.size());
        }
        i.putExtra("duration", (long) info.playable.getDuration());
        i.putExtra("position", (long) info.playable.getPosition());
        sendBroadcast(i);
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Aggregations

FeedItem (de.danoeh.antennapod.core.feed.FeedItem)149 Feed (de.danoeh.antennapod.core.feed.Feed)53 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)40 Date (java.util.Date)35 ArrayList (java.util.ArrayList)33 PodDBAdapter (de.danoeh.antennapod.core.storage.PodDBAdapter)28 Cursor (android.database.Cursor)23 File (java.io.File)18 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)15 Context (android.content.Context)12 FlakyTest (android.test.FlakyTest)11 View (android.view.View)10 Playable (de.danoeh.antennapod.core.util.playback.Playable)7 Intent (android.content.Intent)6 LayoutInflater (android.view.LayoutInflater)5 ListView (android.widget.ListView)5 SharedPreferences (android.content.SharedPreferences)4 Chapter (de.danoeh.antennapod.core.feed.Chapter)4 FeedFilter (de.danoeh.antennapod.core.feed.FeedFilter)4 LongList (de.danoeh.antennapod.core.util.LongList)4