Catch RuntimeException thrown by MediaPlayer constructor

This commit is contained in:
daniel oeh 2013-08-23 14:58:09 +02:00
parent eeec2d846f
commit e8d0abe954
1 changed files with 8 additions and 2 deletions

View File

@ -828,8 +828,9 @@ public class DownloadService extends Service {
media.setFile_url(request.getDestination());
// Get duration
MediaPlayer mediaplayer = new MediaPlayer();
MediaPlayer mediaplayer = null;
try {
mediaplayer = new MediaPlayer();
mediaplayer.setDataSource(media.getFile_url());
mediaplayer.prepare();
media.setDuration(mediaplayer.getDuration());
@ -838,8 +839,13 @@ public class DownloadService extends Service {
mediaplayer.reset();
} catch (IOException e) {
e.printStackTrace();
} catch (RuntimeException e) {
// Thrown by MediaPlayer initialization on some devices
e.printStackTrace();
} finally {
mediaplayer.release();
if (mediaplayer != null) {
mediaplayer.release();
}
}
if (media.getItem().getChapters() == null) {