- 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
This commit is contained in:
IgorA100
2026-05-31 16:25:51 +03:00
parent 70cfbbf61b
commit a233fc1224
3 changed files with 11 additions and 4 deletions

View File

@@ -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

View File

@@ -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];

View File

@@ -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);