Search in sources :

Example 1 with PlaybackServiceStarter

use of de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter in project AntennaPod by AntennaPod.

the class PlayLocalActionButton method onClick.

@Override
public void onClick(Context context) {
    final FeedMedia media = item.getMedia();
    if (media == null) {
        return;
    }
    new PlaybackServiceStarter(context, media).callEvenIfRunning(true).startWhenPrepared(true).shouldStream(true).start();
    if (media.getMediaType() == MediaType.VIDEO) {
        context.startActivity(PlaybackService.getPlayerActivityIntent(context, media));
    }
}
Also used : PlaybackServiceStarter(de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia)

Example 2 with PlaybackServiceStarter

use of de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter in project AntennaPod by AntennaPod.

the class AutoDownloadTest method playEpisode.

private void playEpisode(@NonNull FeedItem item) {
    FeedMedia media = item.getMedia();
    new PlaybackServiceStarter(context, media).callEvenIfRunning(true).startWhenPrepared(true).shouldStream(true).start();
    Awaitility.await("episode is playing").atMost(2000, MILLISECONDS).until(() -> item.getMedia().getId() == PlaybackPreferences.getCurrentlyPlayingFeedMediaId());
}
Also used : PlaybackServiceStarter(de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia)

Example 3 with PlaybackServiceStarter

use of de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter 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");
        PlaybackPreferences.writeNoMediaPlaying();
        return null;
    }
    Log.d(TAG, "getNextInQueue()");
    FeedMedia media = (FeedMedia) currentMedia;
    if (media.getItem() == null) {
        media.setItem(DBReader.getFeedItem(media.getItemId()));
    }
    FeedItem item = media.getItem();
    if (item == null) {
        Log.w(TAG, "getNextInQueue() with FeedMedia object whose FeedItem is null");
        PlaybackPreferences.writeNoMediaPlaying();
        return null;
    }
    FeedItem nextItem;
    nextItem = DBReader.getNextInQueue(item);
    if (nextItem == null || nextItem.getMedia() == null) {
        PlaybackPreferences.writeNoMediaPlaying();
        return null;
    }
    if (!UserPreferences.isFollowQueue()) {
        Log.d(TAG, "getNextInQueue(), but follow queue is not enabled.");
        PlaybackPreferences.writeMediaPlaying(nextItem.getMedia(), PlayerStatus.STOPPED, false);
        updateNotificationAndMediaSession(nextItem.getMedia());
        return null;
    }
    if (!nextItem.getMedia().localFileAvailable() && !NetworkUtils.isStreamingAllowed() && UserPreferences.isFollowQueue() && !nextItem.getFeed().isLocalFeed()) {
        displayStreamingNotAllowedNotification(new PlaybackServiceStarter(this, nextItem.getMedia()).prepareImmediately(true).startWhenPrepared(true).shouldStream(true).getIntent());
        PlaybackPreferences.writeNoMediaPlaying();
        stateManager.stopService();
        return null;
    }
    return nextItem.getMedia();
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) PlaybackServiceStarter(de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter) FeedMedia(de.danoeh.antennapod.model.feed.FeedMedia)

Example 4 with PlaybackServiceStarter

use of de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter in project AntennaPod by AntennaPod.

the class PlaybackService method startPlayingFromPreferences.

private void startPlayingFromPreferences() {
    Observable.fromCallable(() -> PlayableUtils.createInstanceFromPreferences(getApplicationContext())).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(playable -> {
        boolean localFeed = URLUtil.isContentUrl(playable.getStreamUrl());
        if (PlaybackPreferences.getCurrentEpisodeIsStream() && !NetworkUtils.isStreamingAllowed() && !localFeed) {
            displayStreamingNotAllowedNotification(new PlaybackServiceStarter(this, playable).prepareImmediately(true).startWhenPrepared(true).shouldStream(true).getIntent());
            PlaybackPreferences.writeNoMediaPlaying();
            stateManager.stopService();
            return;
        }
        mediaPlayer.playMediaObject(playable, PlaybackPreferences.getCurrentEpisodeIsStream(), true, true);
        stateManager.validStartCommandWasReceived();
        updateNotificationAndMediaSession(playable);
        addPlayableToQueue(playable);
    }, error -> {
        Log.d(TAG, "Playable was not loaded from preferences. Stopping service.");
        error.printStackTrace();
        stateManager.stopService();
    });
}
Also used : PlaybackServiceStarter(de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter)

Example 5 with PlaybackServiceStarter

use of de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter in project AntennaPod by AntennaPod.

the class FeedItemlistDescriptionAdapter method getView.

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    Holder holder;
    FeedItem item = getItem(position);
    // Inflate layout
    if (convertView == null) {
        holder = new Holder();
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.itemdescription_listitem, parent, false);
        holder.title = convertView.findViewById(R.id.txtvTitle);
        holder.pubDate = convertView.findViewById(R.id.txtvPubDate);
        holder.description = convertView.findViewById(R.id.txtvDescription);
        holder.preview = convertView.findViewById(R.id.butPreview);
        convertView.setTag(holder);
    } else {
        holder = (Holder) convertView.getTag();
    }
    holder.title.setText(item.getTitle());
    holder.pubDate.setText(DateFormatter.formatAbbrev(getContext(), item.getPubDate()));
    if (item.getDescription() != null) {
        String description = HtmlToPlainText.getPlainText(item.getDescription()).replaceAll("\n", " ").replaceAll("\\s+", " ").trim();
        holder.description.setText(description);
        holder.description.setMaxLines(MAX_LINES_COLLAPSED);
    }
    // not expanded
    holder.description.setTag(Boolean.FALSE);
    holder.preview.setVisibility(View.GONE);
    holder.preview.setOnClickListener(v -> {
        if (item.getMedia() == null) {
            return;
        }
        Playable playable = new RemoteMedia(item);
        if (!NetworkUtils.isStreamingAllowed()) {
            new StreamingConfirmationDialog(getContext(), playable).show();
            return;
        }
        new PlaybackServiceStarter(getContext(), playable).shouldStream(true).startWhenPrepared(true).callEvenIfRunning(true).start();
        if (playable.getMediaType() == MediaType.VIDEO) {
            getContext().startActivity(PlaybackService.getPlayerActivityIntent(getContext(), playable));
        }
    });
    convertView.setOnClickListener(v -> {
        if (holder.description.getTag() == Boolean.TRUE) {
            holder.description.setMaxLines(MAX_LINES_COLLAPSED);
            holder.preview.setVisibility(View.GONE);
            holder.description.setTag(Boolean.FALSE);
        } else {
            holder.description.setMaxLines(30);
            holder.description.setTag(Boolean.TRUE);
            holder.preview.setVisibility(item.getMedia() != null ? View.VISIBLE : View.GONE);
            holder.preview.setText(R.string.preview_episode);
        }
    });
    return convertView;
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) PlaybackServiceStarter(de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter) Playable(de.danoeh.antennapod.model.playback.Playable) LayoutInflater(android.view.LayoutInflater) RemoteMedia(de.danoeh.antennapod.model.playback.RemoteMedia) StreamingConfirmationDialog(de.danoeh.antennapod.dialog.StreamingConfirmationDialog) NonNull(androidx.annotation.NonNull)

Aggregations

PlaybackServiceStarter (de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter)7 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)5 StreamingConfirmationDialog (de.danoeh.antennapod.dialog.StreamingConfirmationDialog)2 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)2 LayoutInflater (android.view.LayoutInflater)1 NonNull (androidx.annotation.NonNull)1 Playable (de.danoeh.antennapod.model.playback.Playable)1 RemoteMedia (de.danoeh.antennapod.model.playback.RemoteMedia)1