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() {
|
private IPlayer createMediaPlayer() {
|
||||||
|
if (player != null) {
|
||||||
|
player.release();
|
||||||
|
}
|
||||||
IPlayer player;
|
IPlayer player;
|
||||||
if (media == null || media.getMediaType() == MediaType.VIDEO) {
|
if (media == null || media.getMediaType() == MediaType.VIDEO) {
|
||||||
player = new VideoPlayer();
|
player = new VideoPlayer();
|
||||||
@ -581,7 +584,6 @@ public class PlaybackService extends Service {
|
|||||||
cancelPositionSaver();
|
cancelPositionSaver();
|
||||||
player.setDisplay(null);
|
player.setDisplay(null);
|
||||||
player.reset();
|
player.reset();
|
||||||
player.release();
|
|
||||||
player = createMediaPlayer();
|
player = createMediaPlayer();
|
||||||
status = PlayerStatus.STOPPED;
|
status = PlayerStatus.STOPPED;
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|
||||||
|
import android.media.MediaMetadataRetriever;
|
||||||
import de.danoeh.antennapod.storage.*;
|
import de.danoeh.antennapod.storage.*;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
@ -25,7 +26,6 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.media.MediaPlayer;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -801,23 +801,21 @@ public class DownloadService extends Service {
|
|||||||
media.setFile_url(request.getDestination());
|
media.setFile_url(request.getDestination());
|
||||||
|
|
||||||
// Get duration
|
// Get duration
|
||||||
MediaPlayer mediaplayer = null;
|
MediaMetadataRetriever mmr = null;
|
||||||
try {
|
try {
|
||||||
mediaplayer = new MediaPlayer();
|
mmr = new MediaMetadataRetriever();
|
||||||
mediaplayer.setDataSource(media.getFile_url());
|
mmr.setDataSource(media.getFile_url());
|
||||||
mediaplayer.prepare();
|
String durationStr = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
|
||||||
media.setDuration(mediaplayer.getDuration());
|
media.setDuration(Integer.parseInt(durationStr));
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Duration of file is " + media.getDuration());
|
Log.d(TAG, "Duration of file is " + media.getDuration());
|
||||||
mediaplayer.reset();
|
} catch (NumberFormatException e) {
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
// Thrown by MediaPlayer initialization on some devices
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (mediaplayer != null) {
|
if (mmr != null) {
|
||||||
mediaplayer.release();
|
mmr.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user