diff --git a/domain/src/main/java/org/m4m/domain/MediaSource.java b/domain/src/main/java/org/m4m/domain/MediaSource.java index 52bf10d..cc883aa 100644 --- a/domain/src/main/java/org/m4m/domain/MediaSource.java +++ b/domain/src/main/java/org/m4m/domain/MediaSource.java @@ -155,6 +155,7 @@ private void drain() { public Iterable getMediaFormats() { LinkedList result = new LinkedList(); for (int i = 0; i < mediaExtractor.getTrackCount(); i++) { + if (mediaExtractor.getTrackFormat(i) == null) continue; result.add(mediaExtractor.getTrackFormat(i)); } return result; @@ -228,7 +229,8 @@ private long getMaxAllTracksDuration() { long maxDuration = 0; int i = 0; for (MediaFormat ignored : getMediaFormats()) { - if (mediaExtractor.getTrackFormat(i).getDuration() > maxDuration) { + if (mediaExtractor.getTrackFormat(i) != null + && (mediaExtractor.getTrackFormat(i).getDuration() > maxDuration)) { maxDuration = mediaExtractor.getTrackFormat(i).getDuration(); } i++; @@ -268,8 +270,12 @@ private boolean isVideoTrack() { } private boolean isVideoTrack(int trackId) { - String mimeType = mediaExtractor.getTrackFormat(trackId).getMimeType(); - return mimeType.startsWith("video"); + if (mediaExtractor.getTrackFormat(trackId) != null) { + String mimeType = mediaExtractor.getTrackFormat(trackId).getMimeType(); + return mimeType.startsWith("video"); + } else { + return false; + } } @Override