summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/service/download/DownloadService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/danoeh/antennapod/service/download/DownloadService.java')
-rw-r--r--src/de/danoeh/antennapod/service/download/DownloadService.java20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/de/danoeh/antennapod/service/download/DownloadService.java b/src/de/danoeh/antennapod/service/download/DownloadService.java
index 4d521b4df..c27b4d4fe 100644
--- a/src/de/danoeh/antennapod/service/download/DownloadService.java
+++ b/src/de/danoeh/antennapod/service/download/DownloadService.java
@@ -11,6 +11,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.xml.parsers.ParserConfigurationException;
+import android.media.MediaMetadataRetriever;
import de.danoeh.antennapod.storage.*;
import org.xml.sax.SAXException;
@@ -25,7 +26,6 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.Handler;
@@ -801,23 +801,21 @@ public class DownloadService extends Service {
media.setFile_url(request.getDestination());
// Get duration
- MediaPlayer mediaplayer = null;
+ MediaMetadataRetriever mmr = null;
try {
- mediaplayer = new MediaPlayer();
- mediaplayer.setDataSource(media.getFile_url());
- mediaplayer.prepare();
- media.setDuration(mediaplayer.getDuration());
+ mmr = new MediaMetadataRetriever();
+ mmr.setDataSource(media.getFile_url());
+ String durationStr = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
+ media.setDuration(Integer.parseInt(durationStr));
if (AppConfig.DEBUG)
Log.d(TAG, "Duration of file is " + media.getDuration());
- mediaplayer.reset();
- } catch (IOException e) {
+ } catch (NumberFormatException e) {
e.printStackTrace();
} catch (RuntimeException e) {
- // Thrown by MediaPlayer initialization on some devices
e.printStackTrace();
} finally {
- if (mediaplayer != null) {
- mediaplayer.release();
+ if (mmr != null) {
+ mmr.release();
}
}