diff --git a/webif/html/browse/script.js b/webif/html/browse/script.js
index 28ad4b1..d3d2754 100755
--- a/webif/html/browse/script.js
+++ b/webif/html/browse/script.js
@@ -781,12 +781,14 @@ $('img.doopt').contextMenu(
// Disable items which are not yet implemented.
$('#optmenu').disableContextMenuItems('#title');
-var $buttons = {
- "Close" : function() {$(this).dialog('close');}
-};
-var $buttonsp = $.extend(
- {"Play" : function() { doplay(); }},
- $buttons);
+var $buttons = [
+ { id: 'close',
+ text: 'Close',
+ click: function() {$(this).dialog('close');}},
+ { id: 'play',
+ text: 'Play',
+ click: function() { doplay(this); };
+];
// Create reusable dialogue.
var $dialog = $('#dialogue').dialog({
@@ -800,16 +802,47 @@ var $dialog = $('#dialogue').dialog({
'Retrieving data...'); }
});
-function doplay()
+function doplay(it)
{
var file = $dialog.attr('file');
var type = $dialog.attr('type');
- disableall();
+ var duration = 0;
+ var fmts = "";
+ var vc = ""
+ var ff = $('#ffmpeg')[0];
+
+ if (ff) {
+ /* extract duration, container and video codec from ffmpeg output */
+ ff = ff.innerHTML;
+ var match = /Duration:\s+([0-9.:]+),/.exec(ff);
+ if (match && match[1])
+ duration = (new Date('1970-01-01T' + match[1] + 'Z')).getTime()/1000;
+ match = /Input #0,\s+([-A-Za-z0-9_,]+),\s/.exec(ff);
+ if (match && match[1]) fmts = match[1];
+ match = /Stream #.+\sVideo:\s+([-A-Za-z0-9_]+)\s/.exec(ff);
+ if (match && match[1]) vc = match[1];
+ }
- window.location = '/play/play.jim?' +
- 'dir=' + encodeURIComponent(dir) +
- '&file=' + encodeURIComponent(file);
+ fmts = /mp4|webm/.exec(fmts);
+ if (fmts && fmts[0])
+ vc = /h264|av1|vp9/.exec(vc);
+ else
+ vc = null;
+
+ if (vc && vc[0]) {
+ /* base on page address to handle client on external network, etc */
+ var hh = new URL(file, window.location.href);
+ window.location = hh.href;
+ } else {
+ window.location = '/play/play.jim?' +
+ 'dir=' + encodeURIComponent(dir) +
+ '&base=' + encodeURI(window.location.href) +
+ '&duration=' + duration +
+ '&file=' + encodeURIComponent(file);
+ }
+
+ $(it).dialog('close');
}
// Bind dialogue open to filenames.
@@ -828,11 +861,9 @@ $('a.bf').click(function(e) {
$dialog.attr('file', file);
$dialog.attr('type', type);
- if (type == 'ts' &&
- (opt.attr('odencd') == 0 || opt.attr('dlna') == 1))
- $dialog.dialog("option", "buttons", $buttonsp);
- else
- $dialog.dialog("option", "buttons", $buttons);
+ if (!(type == 'ts' &&
+ (opt.attr('odencd') == 0 || opt.attr('dlna') == 1)))
+ $('#play').button('disable');
$dialog.dialog('open');
});