This commit is contained in:
parent
7c98dee3cb
commit
241935c601
|
@ -70,7 +70,21 @@ public class LocalFeedUpdater {
|
|||
Set<String> mediaFileNames = new HashSet<>();
|
||||
for (DocumentFile file : documentFolder.listFiles()) {
|
||||
String mime = file.getType();
|
||||
if (mime != null && (mime.startsWith("audio/") || mime.startsWith("video/"))) {
|
||||
if (mime == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
MediaType mediaType = MediaType.fromMimeType(mime);
|
||||
if (mediaType == MediaType.UNKNOWN) {
|
||||
String path = file.getUri().toString();
|
||||
int fileExtensionPosition = path.lastIndexOf('.');
|
||||
if (fileExtensionPosition >= 0) {
|
||||
String extensionWithoutDot = path.substring(fileExtensionPosition + 1);
|
||||
mediaType = MediaType.fromFileExtension(extensionWithoutDot);
|
||||
}
|
||||
}
|
||||
|
||||
if (mediaType == MediaType.AUDIO || mediaType == MediaType.VIDEO) {
|
||||
mediaFiles.add(file);
|
||||
mediaFileNames.add(file.getName());
|
||||
}
|
||||
|
|
|
@ -2,19 +2,55 @@ package de.danoeh.antennapod.core.feed;
|
|||
|
||||
import android.text.TextUtils;
|
||||
|
||||
public enum MediaType {
|
||||
AUDIO, VIDEO, UNKNOWN;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
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;
|
||||
}
|
||||
public enum MediaType {
|
||||
AUDIO, VIDEO, UNKNOWN;
|
||||
|
||||
private static final Set<String> AUDIO_APPLICATION_MIME_STRINGS = new HashSet<>(Arrays.asList(
|
||||
"application/ogg",
|
||||
"application/opus",
|
||||
"application/x-flac"
|
||||
));
|
||||
|
||||
// based on https://developer.android.com/guide/topics/media/media-formats
|
||||
static final Set<String> AUDIO_FILE_EXTENSIONS = new HashSet<>(Arrays.asList(
|
||||
"3gp", "aac", "amr", "flac", "imy", "m4a", "mid", "mkv", "mp3", "mp4", "mxmf", "oga",
|
||||
"ogg", "ogx", "opus", "ota", "rtttl", "rtx", "wav", "xmf"
|
||||
));
|
||||
|
||||
static final Set<String> VIDEO_FILE_EXTENSIONS = new HashSet<>(Arrays.asList(
|
||||
"3gp", "mkv", "mp4", "ogg", "ogv", "ogx", "webm"
|
||||
));
|
||||
|
||||
public static MediaType fromMimeType(String mimeType) {
|
||||
if (TextUtils.isEmpty(mimeType)) {
|
||||
return MediaType.UNKNOWN;
|
||||
} else if (mimeType.startsWith("audio")) {
|
||||
return MediaType.AUDIO;
|
||||
} else if (mimeType.startsWith("video")) {
|
||||
return MediaType.VIDEO;
|
||||
} else if (AUDIO_APPLICATION_MIME_STRINGS.contains(mimeType)) {
|
||||
return MediaType.AUDIO;
|
||||
}
|
||||
return MediaType.UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param extensionWithoutDot the file extension (suffix) without the dot
|
||||
* @return the {@link MediaType} that likely corresponds to the extension. However, since the
|
||||
* extension is not always enough to determine whether a file is an audio or video (3gp
|
||||
* can be both, for example), this may not be correct. As a result, where possible,
|
||||
* {@link #fromMimeType(String) fromMimeType} should always be tried first.
|
||||
*/
|
||||
public static MediaType fromFileExtension(String extensionWithoutDot) {
|
||||
if (AUDIO_FILE_EXTENSIONS.contains(extensionWithoutDot)) {
|
||||
return MediaType.AUDIO;
|
||||
} else if (VIDEO_FILE_EXTENSIONS.contains(extensionWithoutDot)) {
|
||||
return MediaType.VIDEO;
|
||||
}
|
||||
return MediaType.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue