Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
Basic/Classic UI: support for HTTP Live Stream
Browse files Browse the repository at this point in the history
Add support for HLS in compatible WEB browsers
Use encoding="HLS" in the video sitemap element.

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo committed Oct 8, 2017
1 parent d7e2bf5 commit 5c542f7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
Expand Up @@ -4,6 +4,6 @@
data-control-type="video"
data-widget-id="%widget_id%"
>
<video autoplay controls src="%url%"></video>
<video autoplay controls src="%url%" %media_type%></video>
</div>
</div>
Expand Up @@ -9,6 +9,8 @@

import org.apache.commons.lang.StringUtils;
import org.eclipse.emf.common.util.EList;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.model.sitemap.Video;
import org.eclipse.smarthome.model.sitemap.Widget;
import org.eclipse.smarthome.ui.basic.render.RenderException;
Expand Down Expand Up @@ -36,14 +38,22 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderExcep
String widgetId = itemUIRegistry.getWidgetId(w);
String sitemap = w.eResource().getURI().path();

if (videoWidget.getEncoding() != null && videoWidget.getEncoding().contains("mjpeg")) {
if (videoWidget.getEncoding() != null && videoWidget.getEncoding().toLowerCase().contains("mjpeg")) {
// we handle mjpeg streams as an html image as browser can usually handle this
snippet = getSnippet("image");
} else {
snippet = getSnippet("video");
}
String url = "../proxy?sitemap=" + sitemap + "&widgetId=" + widgetId;
String mediaType = "";
if (videoWidget.getEncoding() != null && videoWidget.getEncoding().toLowerCase().contains("hls")) {
// For HTTP Live Stream we don't proxy the URL and we set the appropriate media type
State state = itemUIRegistry.getState(w);
url = (state instanceof StringType) ? state.toString() : videoWidget.getUrl();
mediaType = "type=\"application/vnd.apple.mpegurl\"";
}
snippet = StringUtils.replace(snippet, "%url%", url);
snippet = StringUtils.replace(snippet, "%media_type%", mediaType);
snippet = preprocessSnippet(snippet, videoWidget);

sb.append(snippet);
Expand Down
@@ -1 +1 @@
<p><center><video style="padding:10px;width:90%" autoplay controls src="%url%"/></center></p>
<p><center><video style="padding:10px;width:90%" autoplay controls src="%url%" %media_type%/></center></p>
Expand Up @@ -9,6 +9,8 @@

import org.apache.commons.lang.StringUtils;
import org.eclipse.emf.common.util.EList;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.model.sitemap.Video;
import org.eclipse.smarthome.model.sitemap.Widget;
import org.eclipse.smarthome.ui.classic.render.RenderException;
Expand Down Expand Up @@ -45,7 +47,15 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderExcep
snippet = getSnippet("video");
}
String url = "../proxy?sitemap=" + sitemap + "&widgetId=" + widgetId;
String mediaType = "";
if (videoWidget.getEncoding() != null && videoWidget.getEncoding().toLowerCase().contains("hls")) {
// For HTTP Live Stream we don't proxy the URL and we set the appropriate media type
State state = itemUIRegistry.getState(w);
url = (state instanceof StringType) ? state.toString() : videoWidget.getUrl();
mediaType = "type=\"application/vnd.apple.mpegurl\"";
}
snippet = StringUtils.replace(snippet, "%url%", url);
snippet = StringUtils.replace(snippet, "%media_type%", mediaType);
sb.append(snippet);
return null;
}
Expand Down

0 comments on commit 5c542f7

Please sign in to comment.