Skip to content

Commit

Permalink
browser: notify user for unsupported video
Browse files Browse the repository at this point in the history
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 <[email protected]>
Change-Id: I22bfc836a98ec0eb2caa58b89332b2531d69d18f
  • Loading branch information
lpranam committed Oct 11, 2023
1 parent 6eb60ac commit 055fca1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
47 changes: 47 additions & 0 deletions browser/src/layer/vector/SVGGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* L.SVGGroup
*/

/* global _ */

L.SVGGroup = L.Layer.extend({

options: {
Expand Down Expand Up @@ -78,6 +80,51 @@ 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 source = video.getElementsByTagName('source');
source = source ? source[0] : undefined;
if (video.networkState === 3) { // 3 = NETWORK_NO_SOURCE = No HTMLMediaElement src found
this.showUnsupportedVideoWarning();
break;
}

video.addEventListener('playing', function() {
window.setTimeout(function() {
if (video.webkitDecodedFrameCount === 0) {
that.showUnsupportedVideoWarning();
}
}, 1000);
});

video.addEventListener('error', function() {
that.showUnsupportedVideoWarning();
});

if (source) {
source.addEventListener('error', function() {
that.showUnsupportedVideoWarning();
});
}
}

},

showUnsupportedVideoWarning: function() {
var videoWarning = _('Document contains unsupported video');
L.Map.THIS.uiManager.showSnackbar(videoWarning);
},

addEmbeddedSVG: function (svgString) {
Expand Down
6 changes: 6 additions & 0 deletions browser/src/map/handler/Map.SlideShow.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ L.Map.SlideShow = L.Handler.extend({
var separator = (this._slideURL.indexOf('?') === -1) ? '?' : '&';
this._slideShow.src = this._slideURL + separator + 'StartSlideNumber=' + this._startSlideNumber;
this._slideShow.contentWindow.focus();

var that = this;
this._slideShow.addEventListener('load', function() {
var videos = that._slideShow.contentWindow.document.getElementsByTagName('video');
L.SVGGroup.prototype.addVideoSupportHandlers(videos);
});
},

_processSlideshowLinks: function() {
Expand Down

0 comments on commit 055fca1

Please sign in to comment.