From 1be62a5c912a2a970f22ad463b1811f008ea57ca Mon Sep 17 00:00:00 2001 From: Tom Yan Date: Wed, 4 Apr 2018 17:55:21 +0800 Subject: [PATCH] MediaPlayerAPI: remove extension pattern check There are way more possibilities and extension doesn't guarantee anything about the file. --- .../java/com/termux/api/MediaPlayerAPI.java | 36 ++++++------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/termux/api/MediaPlayerAPI.java b/app/src/main/java/com/termux/api/MediaPlayerAPI.java index 04cac4e..2b942e9 100644 --- a/app/src/main/java/com/termux/api/MediaPlayerAPI.java +++ b/app/src/main/java/com/termux/api/MediaPlayerAPI.java @@ -14,7 +14,6 @@ import com.termux.api.util.TermuxApiLogger; import java.io.File; import java.io.IOException; import java.io.PrintWriter; -import java.util.regex.Pattern; /** * API that enables playback of standard audio formats such as: @@ -171,17 +170,6 @@ public class MediaPlayerAPI { }); } - /** - * Checks to see if the specified file exists and is a supported media type - * @param file - * @return - */ - protected static boolean isValidMediaFile(File file) { - final String MEDIA_PATTERN = ".3gp|.flac|.mkv|.mp3|.ogg|.wav$"; - Pattern pattern = Pattern.compile(MEDIA_PATTERN); - return pattern.matcher(file.getName()).find(); - } - /** * ----- * Media Command Handlers @@ -210,20 +198,16 @@ public class MediaPlayerAPI { File mediaFile = new File(intent.getStringExtra("file")); - if (!isValidMediaFile(mediaFile)) { - result.error = "Invalid file: " + mediaFile.getName(); - } else { - if (player.isPlaying()) { - player.stop(); - player.reset(); - } - try { - player.setDataSource(context, Uri.fromFile(mediaFile)); - player.prepareAsync(); - result.message = "Now Playing: " + mediaFile.getName(); - } catch (IOException e) { - result.error = e.getMessage(); - } + if (player.isPlaying()) { + player.stop(); + player.reset(); + } + try { + player.setDataSource(context, Uri.fromFile(mediaFile)); + player.prepareAsync(); + result.message = "Now Playing: " + mediaFile.getName(); + } catch (IOException e) { + result.error = e.getMessage(); } return result; }