private String mkPage(String id, HttpExchange t) throws IOException {
boolean flowplayer = true;
LOGGER.debug("make play page " + id);
RootFolder root = parent.getRoot(RemoteUtil.userName(t), t);
if (root == null) {
throw new IOException("Unknown root");
}
List<DLNAResource> res = root.getDLNAResources(id, false, 0, 0, root.getDefaultRenderer());
if (res == null || res.isEmpty()) {
LOGGER.debug("Bad id in web if " + id);
throw new IOException("Bad Id");
}
DLNAResource r = res.get(0);
String auto = " autoplay>";
// next/prev handling
String dir = RemoteUtil.getQueryVars(t.getRequestURI().getQuery(), "nxt");
if (StringUtils.isNotEmpty(dir)) {
// if the "nxt" field is set we should calculate the next media
// 1st fetch or own index in the child list
List<DLNAResource> children = r.getParent().getChildren();
int i = children.indexOf(r);
DLNAResource n = null;
int inc;
int loopPos;
if (dir.equals("next")) {
inc = 1;
loopPos = 0;
} else {
inc = -1;
loopPos = children.size() - 1;
}
n = findNext(i + inc, inc, children);
if (n == null && configuration.getWebAutoLoop(r.getFormat())) {
// we were last/first so if we loop pick first/last in list
n = findNext(loopPos, inc, children);
}
if (n != null) {
// all done, change the id
id = n.getResourceId();
r = n;
} else {
// trick here to stop continuing if loop is off
auto = ">";
}
}
String id1 = URLEncoder.encode(id, "UTF-8");
String rawId = id;
String nxtJs = "window.location.replace('/play/" + id1 + "?nxt=next');";
String prvJs = "window.location.replace('/play/" + id1 + "?nxt=prev');";
// hack here to ensure we got a root folder to use for recently played etc.
root.getDefaultRenderer().setRootFolder(root);
String mime = root.getDefaultRenderer().getMimeType(r.mimeType());
String mediaType = "";
String coverImage = "";
if (r instanceof VirtualVideoAction) {
// for VVA we just call the enable fun directly
// waste of resource to play dummy video