Merge pull request #4162 from ByteHamster/fixes-without-duration

Various fixes for feeds that do not specify duration
This commit is contained in:
H. Lehmann 2020-05-16 23:26:22 +02:00 committed by GitHub
commit 20678a94cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 7 deletions

View File

@ -7,15 +7,11 @@ import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import androidx.cardview.widget.CardView; import androidx.cardview.widget.CardView;
import androidx.core.view.AccessibilityDelegateCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.joanzapata.iconify.Iconify; import com.joanzapata.iconify.Iconify;
@ -201,6 +197,7 @@ public class EpisodeItemViewHolder extends RecyclerView.ViewHolder {
progressBar.setProgress((int) (100.0 * event.getPosition() / event.getDuration())); progressBar.setProgress((int) (100.0 * event.getPosition() / event.getDuration()));
position.setText(Converter.getDurationStringLong(event.getPosition())); position.setText(Converter.getDurationStringLong(event.getPosition()));
duration.setText(Converter.getDurationStringLong(event.getDuration())); duration.setText(Converter.getDurationStringLong(event.getDuration()));
duration.setVisibility(View.VISIBLE); // Even if the duration was previously unknown, it is now known
} }
/** /**

View File

@ -224,7 +224,7 @@ public class FeedMedia extends FeedFile implements Playable {
public boolean hasAlmostEnded() { public boolean hasAlmostEnded() {
int smartMarkAsPlayedSecs = UserPreferences.getSmartMarkAsPlayedSecs(); int smartMarkAsPlayedSecs = UserPreferences.getSmartMarkAsPlayedSecs();
return this.position >= this.duration - smartMarkAsPlayedSecs * 1000; return this.duration > 0 && this.position >= this.duration - smartMarkAsPlayedSecs * 1000;
} }
@Override @Override

View File

@ -48,6 +48,7 @@ import java.util.concurrent.TimeUnit;
import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.event.FeedItemEvent;
import de.danoeh.antennapod.core.event.MessageEvent; import de.danoeh.antennapod.core.event.MessageEvent;
import de.danoeh.antennapod.core.event.PlaybackPositionEvent; import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
import de.danoeh.antennapod.core.event.ServiceEvent; import de.danoeh.antennapod.core.event.ServiceEvent;
@ -523,7 +524,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
Context context = getApplicationContext(); Context context = getApplicationContext();
if (skipIntro > 0 && playable.getPosition() < skipIntro * 1000) { if (skipIntro > 0 && playable.getPosition() < skipIntro * 1000) {
int duration = getDuration(); int duration = getDuration();
if (skipIntro * 1000 < duration) { if (skipIntro * 1000 < duration || duration <= 0) {
Log.d(TAG, "skipIntro " + playable.getEpisodeTitle()); Log.d(TAG, "skipIntro " + playable.getEpisodeTitle());
mediaPlayer.seekTo(skipIntro * 1000); mediaPlayer.seekTo(skipIntro * 1000);
String skipIntroMesg = context.getString(R.string.pref_feed_skip_intro_toast, String skipIntroMesg = context.getString(R.string.pref_feed_skip_intro_toast,
@ -847,6 +848,17 @@ public class PlaybackService extends MediaBrowserServiceCompat {
return true; return true;
case MediaPlayer.MEDIA_INFO_BUFFERING_END: case MediaPlayer.MEDIA_INFO_BUFFERING_END:
sendNotificationBroadcast(NOTIFICATION_TYPE_BUFFER_END, 0); sendNotificationBroadcast(NOTIFICATION_TYPE_BUFFER_END, 0);
Playable playable = getPlayable();
if (getPlayable() instanceof FeedMedia
&& playable.getDuration() <= 0 && mediaPlayer.getDuration() > 0) {
// Playable is being streamed and does not have a duration specified in the feed
playable.setDuration(mediaPlayer.getDuration());
DBWriter.setFeedMedia((FeedMedia) playable);
updateMediaSessionMetadata(playable);
setupNotification(playable);
}
return true; return true;
default: default:
return flavorHelper.onMediaPlayerInfo(PlaybackService.this, code, resourceId); return flavorHelper.onMediaPlayerInfo(PlaybackService.this, code, resourceId);
@ -1087,7 +1099,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences(); FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences();
int skipEnd = preferences.getFeedSkipEnding(); int skipEnd = preferences.getFeedSkipEnding();
if (skipEnd > 0 if (skipEnd > 0
&& skipEnd < playable.getDuration() && skipEnd < getDuration()
&& (remainingTime - (skipEnd * 1000) > 0) && (remainingTime - (skipEnd * 1000) > 0)
&& ((remainingTime - skipEnd * 1000) < (getCurrentPlaybackSpeed() * 1000))) { && ((remainingTime - skipEnd * 1000) < (getCurrentPlaybackSpeed() * 1000))) {
Log.d(TAG, "skipEndingIfNecessary: Skipping the remaining " + remainingTime + " " + skipEnd * 1000 + " speed " + getCurrentPlaybackSpeed()); Log.d(TAG, "skipEndingIfNecessary: Skipping the remaining " + remainingTime + " " + skipEnd * 1000 + " speed " + getCurrentPlaybackSpeed());