Skip to content

Commit

Permalink
Merge pull request #678 from Merudo/convertUri
Browse files Browse the repository at this point in the history
Now supports Windows file paths (and should support Mac & Linux as well) through URLDecoder class.
  • Loading branch information
Phergus authored Sep 13, 2019
2 parents c45f55b + bf3f2d1 commit 034aa70
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.*;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import javafx.animation.KeyFrame;
Expand Down Expand Up @@ -409,4 +406,34 @@ private void updateMute() {
public static boolean getGlobalMute() {
return globalMute;
}

/**
* Convert a string into a uri string. Spaces are replaced by %20, among other things
*
* @param string the string to convert
* @return the converted string
*/
public static String convertToURI(Object string) {
String strUri = string.toString().trim();
if (!isWeb(strUri) && !strUri.toUpperCase().startsWith("FILE")) {
strUri = "FILE:/" + strUri;
}

try {
String decodedURL = URLDecoder.decode(strUri, "UTF-8");
URL url = new URL(decodedURL);
URI uri =
new URI(
url.getProtocol(),
url.getUserInfo(),
url.getHost(),
url.getPort(),
url.getPath(),
url.getQuery(),
url.getRef());
return uri.toString();
} catch (Exception ex) {
return strUri;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> arg
if (functionName.equalsIgnoreCase("playStream")) {
FunctionUtil.checkNumberParam(functionName, args, 1, 5);
if (!AppPreferences.getPlayStreams()) return -1; // do nothing if disabled in preferences
String strUri = args.get(0).toString();
String strUri = MediaPlayerAdapter.convertToURI(args.get(0));
int cycleCount = psize > 1 ? FunctionUtil.paramAsInteger(functionName, args, 1, true) : 1;
double volume = psize > 2 ? FunctionUtil.paramAsDouble(functionName, args, 2, true) : 1;
double start = psize > 3 ? FunctionUtil.paramAsDouble(functionName, args, 3, true) * 1000 : 0;
Expand All @@ -58,7 +58,7 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> arg
: BigDecimal.ZERO;
} else if (functionName.equalsIgnoreCase("editStream")) {
FunctionUtil.checkNumberParam(functionName, args, 2, 5);
String strUri = args.get(0).toString();
String strUri = MediaPlayerAdapter.convertToURI(args.get(0));

Integer cycleCount = null;
Double volume = null;
Expand All @@ -78,14 +78,14 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> arg
return "";
} else if (functionName.equalsIgnoreCase("stopStream")) {
FunctionUtil.checkNumberParam(functionName, args, 0, 3);
String strUri = psize > 0 ? args.get(0).toString() : "*";
String strUri = psize > 0 ? MediaPlayerAdapter.convertToURI(args.get(0)) : "*";
boolean del = psize > 1 ? FunctionUtil.paramAsBoolean(functionName, args, 1, true) : true;
double fade = psize > 2 ? FunctionUtil.paramAsDouble(functionName, args, 2, true) * 1000 : 0;
MediaPlayerAdapter.stopStream(strUri, del, fade);
return "";
} else if (functionName.equalsIgnoreCase("getStreamProperties")) {
FunctionUtil.checkNumberParam(functionName, args, 0, 1);
String strUri = psize > 0 ? args.get(0).toString() : "*";
String strUri = psize > 0 ? MediaPlayerAdapter.convertToURI(args.get(0)) : "*";
return MediaPlayerAdapter.getStreamProperties(strUri);
}
return null;
Expand Down

0 comments on commit 034aa70

Please sign in to comment.