Catch exception when reading duration via metadata retriever

This commit is contained in:
Martin Fietz 2017-05-01 18:06:09 +02:00
parent 932748ef70
commit 2a2b5fec90
1 changed files with 6 additions and 5 deletions

View File

@ -972,17 +972,18 @@ public class DownloadService extends Service {
// Get duration // Get duration
MediaMetadataRetriever mmr = new MediaMetadataRetriever(); MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(media.getFile_url()); String durationStr = null;
String durationStr = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
try { try {
mmr.setDataSource(media.getFile_url());
durationStr = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
media.setDuration(Integer.parseInt(durationStr)); media.setDuration(Integer.parseInt(durationStr));
Log.d(TAG, "Duration of file is " + media.getDuration()); Log.d(TAG, "Duration of file is " + media.getDuration());
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.d(TAG, "Invalid file duration: " + durationStr); Log.d(TAG, "Invalid file duration: " + durationStr);
} catch(Exception e) {
Log.e(TAG, "Get duration failed", e);
} finally { } finally {
if (mmr != null) { mmr.release();
mmr.release();
}
} }
final FeedItem item = media.getItem(); final FeedItem item = media.getItem();