From a233fc1224a4eae344880d1f278b2d5a2aad757d Mon Sep 17 00:00:00 2001 From: IgorA100 Date: Sun, 31 May 2026 16:25:51 +0300 Subject: [PATCH] - Correct HLS playback on the Watch page - When executing Event->Length() , get the duration of the recorded event file if the duration in the database table is 0 - If native HLS playback fails in Safari, we first try playing MP4, and only if MP4 playback fails do we switch to MJPEG playback --- web/ajax/watch.php | 4 ++-- web/includes/Event.php | 2 +- web/skins/classic/js/skin.js | 9 ++++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/web/ajax/watch.php b/web/ajax/watch.php index d53ce6858..61b5c738e 100644 --- a/web/ajax/watch.php +++ b/web/ajax/watch.php @@ -90,9 +90,9 @@ if ($rows) { $videoAttr = ''; if ($event->DefaultVideo()) { $videoSrc = $event->getStreamSrc(array('mode'=>'mp4'), '&'); - $videoHlsSrc = $event->getStreamSrc(array('mode'=>'hls'), '&'); + $videoHlsSrc = $event->getStreamSrc(array('mode'=>'mp4hls'), '&'); $videoDuration = htmlspecialchars((string)$event->Length()); - $videoAttr = ' video_src="' .$videoSrc. '" data-video-hls-src="' .$videoHlsSrc. '" data-video-duration="' .$videoDuration. '" data-event-start="'.htmlspecialchars($event->StartDateTime()).'"'; + $videoAttr = ' video_src="' .$videoSrc. '" data-video-hls-src="' .$videoHlsSrc. '" data-video-duration-secs="' .$videoDuration. '" data-event-start="'.htmlspecialchars($event->StartDateTime()).'"'; } // Modify the row data as needed diff --git a/web/includes/Event.php b/web/includes/Event.php index b5155c5cb..306df2ffd 100644 --- a/web/includes/Event.php +++ b/web/includes/Event.php @@ -111,7 +111,7 @@ class Event extends ZM_Object { public function Length(){ $duration = 0; - if(! isset($this->{'Length'})){ + if ( !isset($this->{'Length'}) || (float)$this->{'Length'} <= 0 ) { $files = glob($this->Path().'{/incomplete.*,/'.$this->{'Id'}.'-video.*}', GLOB_NOSORT | GLOB_BRACE); if (count($files) > 0) { $file = $files[0]; diff --git a/web/skins/classic/js/skin.js b/web/skins/classic/js/skin.js index fa39be27e..889628677 100644 --- a/web/skins/classic/js/skin.js +++ b/web/skins/classic/js/skin.js @@ -1776,9 +1776,16 @@ function playEventHLS(container, img, monitorId, fallbackToMjpeg, statusBar, eve video.addEventListener('error', function(e) { console.error(e); video.remove(); - fallbackToMjpeg(); + clearTimeout(video._fallbackTimer); + tryPlayMp4(container, img, monitorId, fallbackToMjpeg, statusBar); }); thumbnailVideoPlay(video, 'Native HLS', eventStart, statusBar); + video._fallbackTimer = setTimeout(function() { + if (video.readyState < 2) { + video.remove(); + tryPlayMp4(container, img, monitorId, fallbackToMjpeg, statusBar); + } + }, 2000); } else { video.remove(); tryPlayMp4(container, img, monitorId, fallbackToMjpeg, statusBar);