Как правильно загружать изображение каждые 5 секунд?

У меня есть простой код, который:
— подключиться к моей камере видеонаблюдения в доме
— сделать снимок в формате jpg
— обновлять каждые 5 секунд и показывать новую картинку

Работает нормально, когда я дома, но через интернет при медленном соединении я вижу только первое изображение.

Возможно медленное соединение и 5 секунд не хватило для передачи фото, тогда еще запрос?

Как я могу решить эту проблему? Может быть, изменить этот скрипт, чтобы ждать 5 секунд, но считайте от времени, когда фотография полностью загружена?

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Dom</title>

<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">

</head>
<body>
<h1>Niepołomice</h1>


<script>
function refresh_image(){
var newImage = "http://user:password@192.168.0.20/Streaming/channels/1/picture?" + new Date().getTime();
$("#myImage").attr("src", newImage);
}
setInterval(function(){refresh_image()}, 5000);
</script>

<IMG id="myImage" class="myImage" SRC='currentimage.php'>

<div id="odswiez"></div>


<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>

Currenimage.php (эта часть, вероятно, хорошо):

<?php
while (@ob_end_clean());
header('Content-type: image/jpeg');
// create curl resource
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_URL, 'http://192.168.0.21/Streaming/channels/1/picture');
curl_setopt($ch, CURLOPT_HEADER, 0);
//curl_setopt($ch, CURLOPT_POSTFIELDS, '?1234&status=false');  <- disabling this line helped to make it work!! However, GetData.cgi needs these parameters.
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'user:password');
// $output contains the output string
$output = curl_exec($ch);
echo $output;
// close curl resource to free up system resources
curl_close($ch);
?>

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector