summaryrefslogtreecommitdiff
path: root/src/de/podfetcher
diff options
context:
space:
mode:
authordaniel <daniel@danielpc>2012-06-05 22:01:34 +0200
committerdaniel <daniel@danielpc>2012-06-05 22:01:34 +0200
commitbaca017e2ad47997660bd2ca9d38581b71dcd615 (patch)
tree9f3eddd39dc2e259123fa147fbecf98a7c87f35e /src/de/podfetcher
parentcc77c9dde3d78f37981073e7b40ae0caa0c21b60 (diff)
downloadAntennaPod-baca017e2ad47997660bd2ca9d38581b71dcd615.zip
Duration of mediafile is now looked up when download finishes
Diffstat (limited to 'src/de/podfetcher')
-rw-r--r--src/de/podfetcher/service/DownloadService.java17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/de/podfetcher/service/DownloadService.java b/src/de/podfetcher/service/DownloadService.java
index 074da4694..ab4629f85 100644
--- a/src/de/podfetcher/service/DownloadService.java
+++ b/src/de/podfetcher/service/DownloadService.java
@@ -7,6 +7,7 @@
package de.podfetcher.service;
import java.io.File;
+import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@@ -16,6 +17,7 @@ import android.app.Service;
import android.app.DownloadManager;
import android.content.Intent;
import android.content.IntentFilter;
+import android.media.MediaPlayer;
import android.os.IBinder;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -34,6 +36,9 @@ public class DownloadService extends Service {
private ExecutorService syncExecutor;
private DownloadRequester requester;
private FeedManager manager;
+
+ /** Needed to determine the duration of a media file */
+ private MediaPlayer mediaplayer;
// Objects for communication
@@ -49,6 +54,7 @@ public class DownloadService extends Service {
syncExecutor = Executors.newSingleThreadExecutor();
manager = FeedManager.getInstance();
requester = DownloadRequester.getInstance();
+ mediaplayer = new MediaPlayer();
}
@Override
@@ -60,6 +66,7 @@ public class DownloadService extends Service {
public void onDestroy() {
Log.d(TAG, "Service shutting down");
sendBroadcast(new Intent(ACTION_FEED_SYNC_COMPLETED));
+ mediaplayer.release();
}
private IntentFilter createIntentFilter() {
@@ -140,6 +147,16 @@ public class DownloadService extends Service {
private void handleCompletedFeedMediaDownload(Context context, FeedMedia media) {
Log.d(TAG, "Handling completed FeedMedia Download");
requester.removeFeedMedia(media);
+ // Get duration
+ try {
+ mediaplayer.setDataSource(media.getFile_url());
+ mediaplayer.prepare();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ media.setDuration(mediaplayer.getDuration());
+ Log.d(TAG, "Duration of file is " + media.getDuration());
+ mediaplayer.reset();
manager.setFeedMedia(this, media);
}