move MediaType inference from mime_type into MediaType class

This commit is contained in:
Domingos Lopes 2016-04-19 23:37:36 -04:00
parent 7caa840331
commit 790f5ac1d0
3 changed files with 18 additions and 25 deletions

View File

@ -201,18 +201,7 @@ public class RemoteMedia implements Playable {
@Override @Override
public MediaType getMediaType() { public MediaType getMediaType() {
if (TextUtils.isEmpty(mime_type)) { return MediaType.fromMimeType(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;
} }
@Override @Override

View File

@ -153,18 +153,7 @@ public class FeedMedia extends FeedFile implements Playable {
* Uses mimetype to determine the type of media. * Uses mimetype to determine the type of media.
*/ */
public MediaType getMediaType() { public MediaType getMediaType() {
if (mime_type == null || mime_type.isEmpty()) { return MediaType.fromMimeType(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;
} }
public void updateFromOther(FeedMedia other) { public void updateFromOther(FeedMedia other) {

View File

@ -1,5 +1,20 @@
package de.danoeh.antennapod.core.feed; package de.danoeh.antennapod.core.feed;
import android.text.TextUtils;
public enum MediaType { 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;
}
} }