Skip to content

Commit

Permalink
Правит инициализацию перемотки в подкасте (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
monochromer authored Sep 15, 2023
1 parent 601a20b commit b609f09
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/scripts/modules/podcast.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ function setTime(time) {
player.currentTime = time;
}

/** Перемотка аудио назад на `seconds` секунд
* @param seconds количество секунд
*/
function rewindAudio(seconds) {
if (player.duration && !isNaN(player.duration)) {
const currentTime = player.currentTime;
const targetTime = currentTime + seconds;

player.currentTime = targetTime;
}
}

function handlePassedTimecode() {
const passed = matchTimecode(document.URL);

Expand Down Expand Up @@ -61,24 +73,13 @@ if (player) {
handlePassedTimecode();
}
initAnchor();
}

backButton.addEventListener('click', () => {
rewindAudio(-10);
});

forwardButton.addEventListener('click', () => {
rewindAudio(10);
});

/** Перемотка аудио назад на `seconds` секунд
* @param seconds количество секунд
*/
function rewindAudio(seconds) {
if (player.duration && !isNaN(player.duration)) {
const currentTime = player.currentTime;
const targetTime = currentTime + seconds;
backButton.addEventListener('click', () => {
rewindAudio(-10);
});

player.currentTime = targetTime;
}
forwardButton.addEventListener('click', () => {
rewindAudio(10);
});
}

0 comments on commit b609f09

Please sign in to comment.