From 65611129e15f6a8b8f1a260f373bb6e89fc0c3ea Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Sun, 12 Jul 2015 21:17:22 +0200 Subject: [PATCH] Use local file size if episode is downloaded --- .../core/service/FeedMediaSizeService.java | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/FeedMediaSizeService.java b/core/src/main/java/de/danoeh/antennapod/core/service/FeedMediaSizeService.java index d6a1ce62c..e64a38901 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/FeedMediaSizeService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/FeedMediaSizeService.java @@ -4,6 +4,7 @@ import android.app.IntentService; import android.content.Intent; import android.util.Log; +import java.io.File; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; @@ -36,20 +37,27 @@ public class FeedMediaSizeService extends IntentService { return; } long size = Integer.MIN_VALUE; - HttpURLConnection conn = null; - try { - URL url = new URL(media.getDownload_url()); - conn = (HttpURLConnection) url.openConnection(); - conn.setRequestProperty( "Accept-Encoding", "" ); - conn.setRequestMethod("HEAD"); - size = conn.getContentLength(); - conn.disconnect(); - } catch (IOException e) { - Log.d(TAG, media.getDownload_url()); - e.printStackTrace(); - } finally { - if(conn != null) { + if(media.isDownloaded()) { + File mediaFile = new File(media.getLocalMediaUrl()); + if(mediaFile.exists()) { + size = mediaFile.length(); + } + } else { + HttpURLConnection conn = null; + try { + URL url = new URL(media.getDownload_url()); + conn = (HttpURLConnection) url.openConnection(); + conn.setRequestProperty("Accept-Encoding", ""); + conn.setRequestMethod("HEAD"); + size = conn.getContentLength(); conn.disconnect(); + } catch (IOException e) { + Log.d(TAG, media.getDownload_url()); + e.printStackTrace(); + } finally { + if (conn != null) { + conn.disconnect(); + } } } media.setSize(size);