Skip to content

Commit

Permalink
Merge pull request #191 from kaczmarkiewiczp/streaming-fix
Browse files Browse the repository at this point in the history
Proper encoding of URLs for streaming
  • Loading branch information
patrykcoding authored Aug 1, 2018
2 parents caa9e29 + fb6e03c commit 47533d4
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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) {
Expand Down

0 comments on commit 47533d4

Please sign in to comment.