From 13d7f01e145d175b34f530c238ad02a055755088 Mon Sep 17 00:00:00 2001 From: Pranam Lashkari Date: Fri, 8 Sep 2023 05:44:13 +0800 Subject: [PATCH] browser: notify user for unsupported video detect if video is able to play via checking if any frames are decoded, in other cases(i.e: file not found or corrupted file) check for the errors in source and video Signed-off-by: Pranam Lashkari Change-Id: I22bfc836a98ec0eb2caa58b89332b2531d69d18f --- browser/src/layer/vector/SVGGroup.js | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/browser/src/layer/vector/SVGGroup.js b/browser/src/layer/vector/SVGGroup.js index f347f95940af7..86eff9c4f92f4 100644 --- a/browser/src/layer/vector/SVGGroup.js +++ b/browser/src/layer/vector/SVGGroup.js @@ -3,6 +3,8 @@ * L.SVGGroup */ +/* global _ */ + L.SVGGroup = L.Layer.extend({ options: { @@ -78,6 +80,46 @@ L.SVGGroup = L.Layer.extend({ var point = this._map.latLngToLayerPoint(this._bounds.getNorthWest()); svgLastChild.setAttribute('x', point.x); svgLastChild.setAttribute('y', point.y); + + var videos = svgLastChild.getElementsByTagName('video'); + this.addVideoSupportHandlers(videos); + }, + + addVideoSupportHandlers: function(videos) { + if (!videos) + return; + + var that = this; + + // slide show may have more than one video and it does not require any selection + for (var i = 0; i < videos.length; i++) { + var video = videos[i]; + var sources = video.getElementsByTagName('source'); + + video.addEventListener('playing', function() { + window.setTimeout(function() { + if (video.webkitDecodedFrameCount === 0) { + that.showUnsupportedVideoWarning(); + } + }, 1000); + }); + + video.addEventListener('error', function() { + that.showUnsupportedVideoWarning(); + }); + + if (sources.length) { + sources[0].addEventListener('error', function() { + that.showUnsupportedVideoWarning(); + }); + } + } + + }, + + showUnsupportedVideoWarning: function() { + var videoWarning = _('Document contains unsupported video'); + L.Map.THIS.uiManager.showSnackbar(videoWarning); }, addEmbeddedSVG: function (svgString) {