diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/de/danoeh/antennapod/service/PlaybackService.java | 4 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/service/download/DownloadService.java | 20 |
2 files changed, 12 insertions, 12 deletions
diff --git a/src/de/danoeh/antennapod/service/PlaybackService.java b/src/de/danoeh/antennapod/service/PlaybackService.java index 0bb8753c1..2fa4e10d9 100644 --- a/src/de/danoeh/antennapod/service/PlaybackService.java +++ b/src/de/danoeh/antennapod/service/PlaybackService.java @@ -281,6 +281,9 @@ public class PlaybackService extends Service { } private IPlayer createMediaPlayer() { + if (player != null) { + player.release(); + } IPlayer player; if (media == null || media.getMediaType() == MediaType.VIDEO) { player = new VideoPlayer(); @@ -581,7 +584,6 @@ public class PlaybackService extends Service { cancelPositionSaver(); player.setDisplay(null); player.reset(); - player.release(); player = createMediaPlayer(); status = PlayerStatus.STOPPED; } 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(); } } |