From 790f5ac1d0850757f261f62b747d93e4abf289af Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Tue, 19 Apr 2016 23:37:36 -0400 Subject: [PATCH] move MediaType inference from mime_type into MediaType class --- .../antennapod/core/cast/RemoteMedia.java | 13 +------------ .../danoeh/antennapod/core/feed/FeedMedia.java | 13 +------------ .../danoeh/antennapod/core/feed/MediaType.java | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/cast/RemoteMedia.java b/core/src/main/java/de/danoeh/antennapod/core/cast/RemoteMedia.java index 18e0e3287..99f7b9496 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/cast/RemoteMedia.java +++ b/core/src/main/java/de/danoeh/antennapod/core/cast/RemoteMedia.java @@ -201,18 +201,7 @@ public class RemoteMedia implements Playable { @Override public MediaType getMediaType() { - if (TextUtils.isEmpty(mime_type)) { - return MediaType.UNKNOWN; - } else { - if (mime_type.startsWith("audio")) { - return MediaType.AUDIO; - } else if (mime_type.startsWith("video")) { - return MediaType.VIDEO; - } else if (mime_type.equals("application/ogg")) { - return MediaType.AUDIO; - } - } - return MediaType.UNKNOWN; + return MediaType.fromMimeType(mime_type); } @Override diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java index fa663f7da..7f064fff3 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java @@ -153,18 +153,7 @@ public class FeedMedia extends FeedFile implements Playable { * Uses mimetype to determine the type of media. */ public MediaType getMediaType() { - if (mime_type == null || mime_type.isEmpty()) { - return MediaType.UNKNOWN; - } else { - if (mime_type.startsWith("audio")) { - return MediaType.AUDIO; - } else if (mime_type.startsWith("video")) { - return MediaType.VIDEO; - } else if (mime_type.equals("application/ogg")) { - return MediaType.AUDIO; - } - } - return MediaType.UNKNOWN; + return MediaType.fromMimeType(mime_type); } public void updateFromOther(FeedMedia other) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/MediaType.java b/core/src/main/java/de/danoeh/antennapod/core/feed/MediaType.java index 7b3cb829d..83ac031bf 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/MediaType.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/MediaType.java @@ -1,5 +1,20 @@ package de.danoeh.antennapod.core.feed; +import android.text.TextUtils; + public enum MediaType { - AUDIO, VIDEO, UNKNOWN + AUDIO, VIDEO, UNKNOWN; + + public static MediaType fromMimeType(String mime_type) { + if (TextUtils.isEmpty(mime_type)) { + return MediaType.UNKNOWN; + } else if (mime_type.startsWith("audio")) { + return MediaType.AUDIO; + } else if (mime_type.startsWith("video")) { + return MediaType.VIDEO; + } else if (mime_type.equals("application/ogg")) { + return MediaType.AUDIO; + } + return MediaType.UNKNOWN; + } }