Update Script_Speech_recognition/videoplayer.js
This commit is contained in:
parent
c3b9c5529e
commit
f70f622cd6
@ -4,12 +4,17 @@ const translateWordsBtn = document.getElementById('translateWordsBtn');
|
|||||||
const translateLettersBtn = document.getElementById('translateLettersBtn');
|
const translateLettersBtn = document.getElementById('translateLettersBtn');
|
||||||
const prevBtn = document.getElementById('prevBtn');
|
const prevBtn = document.getElementById('prevBtn');
|
||||||
const nextBtn = document.getElementById('nextBtn');
|
const nextBtn = document.getElementById('nextBtn');
|
||||||
|
const translateBtn = document.getElementById('translateBtn'); // Prelož button
|
||||||
|
|
||||||
let videoSequence = [];
|
let videoSequence = [];
|
||||||
let currentIndex = 0;
|
let currentIndex = 0;
|
||||||
let autoPlayEnabled = true;
|
let autoPlayEnabled = true;
|
||||||
|
|
||||||
function videoExists(src) {
|
// Variable to track the current translation method
|
||||||
|
let currentTranslationMode = 'words'; // Default mode
|
||||||
|
|
||||||
|
// Function to check if video exists
|
||||||
|
async function videoExists(src) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
const video = document.createElement('video');
|
const video = document.createElement('video');
|
||||||
video.src = src;
|
video.src = src;
|
||||||
@ -18,6 +23,7 @@ function videoExists(src) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to load video sequence by words
|
||||||
async function loadVideoSequenceByWords() {
|
async function loadVideoSequenceByWords() {
|
||||||
const words = inputText.value.trim().split(' ');
|
const words = inputText.value.trim().split(' ');
|
||||||
videoSequence = [];
|
videoSequence = [];
|
||||||
@ -31,6 +37,7 @@ async function loadVideoSequenceByWords() {
|
|||||||
currentIndex = 0;
|
currentIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to load video sequence by letters
|
||||||
async function loadVideoSequenceByLetters() {
|
async function loadVideoSequenceByLetters() {
|
||||||
const characters = inputText.value.trim().split('');
|
const characters = inputText.value.trim().split('');
|
||||||
videoSequence = [];
|
videoSequence = [];
|
||||||
@ -46,6 +53,7 @@ async function loadVideoSequenceByLetters() {
|
|||||||
currentIndex = 0;
|
currentIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to play video at a specific index
|
||||||
function playVideoAtIndex(index) {
|
function playVideoAtIndex(index) {
|
||||||
if (index < 0 || index >= videoSequence.length) return;
|
if (index < 0 || index >= videoSequence.length) return;
|
||||||
|
|
||||||
@ -54,8 +62,8 @@ function playVideoAtIndex(index) {
|
|||||||
currentIndex = index;
|
currentIndex = index;
|
||||||
|
|
||||||
// Update the title with the current letter or word
|
// Update the title with the current letter or word
|
||||||
const currentChar = videoSequence[index].split('/').pop().split('.')[0]; // Extract letter from the video path
|
const currentChar = videoSequence[index].split('/').pop().split('.')[0];
|
||||||
document.getElementById('currentLetter').innerText = `Po písmenách ${currentChar.toUpperCase()}`; // Update text
|
document.getElementById('currentLetter').innerText = currentChar.toUpperCase();
|
||||||
|
|
||||||
if (autoPlayEnabled) {
|
if (autoPlayEnabled) {
|
||||||
videoPlayer.onended = () => {
|
videoPlayer.onended = () => {
|
||||||
@ -71,22 +79,37 @@ function playVideoAtIndex(index) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
translateWordsBtn.addEventListener('click', async () => {
|
// Event listener for "Prelož" button (Translate button)
|
||||||
|
translateBtn.addEventListener('click', async () => {
|
||||||
autoPlayEnabled = true;
|
autoPlayEnabled = true;
|
||||||
await loadVideoSequenceByWords();
|
|
||||||
|
// Based on current mode, load the correct video sequence
|
||||||
|
if (currentTranslationMode === 'words') {
|
||||||
|
await loadVideoSequenceByWords();
|
||||||
|
} else if (currentTranslationMode === 'letters') {
|
||||||
|
await loadVideoSequenceByLetters();
|
||||||
|
}
|
||||||
|
|
||||||
if (videoSequence.length > 0) {
|
if (videoSequence.length > 0) {
|
||||||
playVideoAtIndex(currentIndex);
|
playVideoAtIndex(currentIndex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
translateLettersBtn.addEventListener('click', async () => {
|
// Event listener for "Preložiť po slovách" button
|
||||||
autoPlayEnabled = true;
|
translateWordsBtn.addEventListener('click', () => {
|
||||||
await loadVideoSequenceByLetters();
|
currentTranslationMode = 'words'; // Set to words mode
|
||||||
if (videoSequence.length > 0) {
|
translateWordsBtn.classList.add('active'); // Optionally add active class
|
||||||
playVideoAtIndex(currentIndex);
|
translateLettersBtn.classList.remove('active');
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Event listener for "Preložiť po písmenách" button
|
||||||
|
translateLettersBtn.addEventListener('click', () => {
|
||||||
|
currentTranslationMode = 'letters'; // Set to letters mode
|
||||||
|
translateLettersBtn.classList.add('active'); // Optionally add active class
|
||||||
|
translateWordsBtn.classList.remove('active');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Event listeners for prev and next buttons to navigate video sequence
|
||||||
prevBtn.addEventListener('click', () => {
|
prevBtn.addEventListener('click', () => {
|
||||||
if (currentIndex > 0) {
|
if (currentIndex > 0) {
|
||||||
autoPlayEnabled = false;
|
autoPlayEnabled = false;
|
||||||
@ -102,17 +125,3 @@ nextBtn.addEventListener('click', () => {
|
|||||||
playVideoAtIndex(currentIndex);
|
playVideoAtIndex(currentIndex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function hideControls() {
|
|
||||||
if (!videoPlayer.matches(':hover')) {
|
|
||||||
videoPlayer.controls = false;
|
|
||||||
}
|
|
||||||
requestAnimationFrame(hideControls);
|
|
||||||
}
|
|
||||||
|
|
||||||
videoPlayer.addEventListener('mouseenter', () => {
|
|
||||||
videoPlayer.controls = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
hideControls();
|
|
||||||
|
Loading…
Reference in New Issue
Block a user