Made sure not to use multiple unreleased instances of MediaPlayer
This commit is contained in:
parent
c3adcca4d8
commit
8b4834cf23
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue