From fb6e03c54970695c51ab4ca9d755bc26ba1214c1 Mon Sep 17 00:00:00 2001 From: Patryk Kaczmarkiewicz Date: Mon, 30 Jul 2018 22:20:03 -0600 Subject: [PATCH] Proper encoding of URLs for streaming --- .../Fragments/FileExplorerFragment.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/ca/pkay/rcloneexplorer/Fragments/FileExplorerFragment.java b/app/src/main/java/ca/pkay/rcloneexplorer/Fragments/FileExplorerFragment.java index cf74a4e..0c4ea03 100644 --- a/app/src/main/java/ca/pkay/rcloneexplorer/Fragments/FileExplorerFragment.java +++ b/app/src/main/java/ca/pkay/rcloneexplorer/Fragments/FileExplorerFragment.java @@ -1854,22 +1854,26 @@ protected Void doInBackground(FileItem... fileItems) { serveIntent.putExtra(StreamingService.SHOW_NOTIFICATION_TEXT, false); context.startService(serveIntent); - String url = "http://127.0.0.1:8080/" + fileItem.getName(); + Uri uri = Uri.parse("http://127.0.0.1:8080") + .buildUpon() + .appendPath(fileItem.getName()) + .build(); + Intent intent = new Intent(Intent.ACTION_VIEW); // open as takes precedence if (openAs == OPEN_AS_VIDEO) { - intent.setDataAndType(Uri.parse(url), "video/*"); + intent.setDataAndType(uri, "video/*"); } else if (openAs == OPEN_AS_AUDIO) { - intent.setDataAndType(Uri.parse(url), "audio/*"); + intent.setDataAndType(uri, "audio/*"); } else { String type = fileItem.getMimeType(); if (type.startsWith("audio/")) { - intent.setDataAndType(Uri.parse(url), "audio/*"); + intent.setDataAndType(uri, "audio/*"); } else if (type.startsWith("video/")) { - intent.setDataAndType(Uri.parse(url), "video/*"); + intent.setDataAndType(uri, "video/*"); } else { - intent.setData(Uri.parse(url)); + intent.setData(uri); } } @@ -1879,7 +1883,7 @@ protected Void doInBackground(FileItem... fileItems) { int retries = 10; while (retries > 0) { try { - URL checkUrl = new URL(url); + URL checkUrl = new URL(uri.toString()); connection = (HttpURLConnection) checkUrl.openConnection(); code = connection.getResponseCode(); } catch (IOException e) {