Показать сообщение отдельно
  #12 (permalink)  
Старый 19.11.2021, 23:49
Аватар для voraa
Профессор
Отправить личное сообщение для voraa Посмотреть профиль Найти все сообщения от voraa
 
Регистрация: 03.02.2020
Сообщений: 2,712

Сложновато оказалось (давно с видео не работал)
Получилось как то так
(Пример видео - какой нашел в инете не самый короткий

<body>
<video id='video' src='https://www.nlm.nih.gov/web/documentation/TemplateDocumentation/video_files/IN_Intro-800.mp4'>
</video>
<br>
<button id=bs>Start</button>
<script>
let duration;
const start = 20;
const dplay = 3;
const dskip = 7;
const video = document.getElementById('video')

const play = (d) => {
	console.log('play', video.currentTime)
	const te = Math.min(video.currentTime + d, duration)
	const result = !(te === duration)
	return new Promise ((res) => {
		const handl = () => {
			if (video.currentTime > te-0.05) {
				video.removeEventListener('timeupdate', handl)
				res (result);
			}
		}
		video.addEventListener('timeupdate', handl)
		video.play();
	})	
}

const skip = (d) => {
	console.log('skip', video.currentTime)
	const ts = Math.min(video.currentTime + d, duration)
	return new Promise ((res) => {
		if (ts === duration) res (false);
		const handl = () => {
			video.removeEventListener('seeked', handl)
			res (true);
		}
		video.addEventListener('seeked', handl)
		video.currentTime = ts;
	})			
}

const work = async () => {
	let result = true;
	result = await skip (start)
	while (result) {
		result = await play(dplay)
		if (result) result = await skip(dskip)
	}
}

video.addEventListener('durationchange', () => {
	duration = video.duration;
})
document.getElementById('bs').onclick = () => work()
</script>
</body>
Ответить с цитированием