jais créé un site de partage de video mais je voulais utiliser le lecteur flash de youtube pour executer les video, donc corrige le code source php "<?php
// Assurez-vous que le fichier vidéo est bien passé en paramètre
if (!isset($_GET['file'])) {
die('Aucun fichier vidéo spécifié.');
}
videoFile=htmlspecialchars(_GET['file']);
feedbackFile=′feedback/′.md5(videoFile) . '.json';
// Charger les feedbacks spécifiques à cette vidéo
if (!file_exists(feedbackFile)) {
file_put_contents(feedbackFile, json_encode(['comments' => [], 'likes' => 0, 'dislikes' => 0]));
}
feedbackData=jsondecode(ffeedbackFile), true);
feedbackData['comments'] ?? [];
feedbackData['likes'] ?? 0;
feedbackData['dislikes'] ?? 0;
function escapeHtml(string) {
return htmlspecialchars(string, ENT_QUOTES, 'UTF-8');
}
?>
<div class="feedback-container">
<div class="feedback-buttons">
<button id="likeButton">👍 <span id="likeCount"><?php echo $likes; ?></span></button>
<button id="dislikeButton">👎 <span id="dislikeCount"><?php echo $dislikes; ?></span></button>
</div>
<div class="comments" id="comments">
<?php foreach ($comments as $comment): ?>
<div class="comment">
<?php echo escapeHtml($comment); ?>
</div>
<?php endforeach; ?>
</div>
<div class="comment-form">
<textarea id="commentText" placeholder="Écrire un commentaire..."></textarea>
<button id="submitComment">Envoyer</button>
</div>
</div>
<script>
const video = document.getElementById('video');
const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
const playPauseButton = document.getElementById('playPause');
const progressBar = document.getElementById('progressBar');
const progress = document.getElementById('progress');
const volumeControl = document.getElementById('volumeControl');
const volumeProgress = document.getElementById('volumeProgress');
const likeButton = document.getElementById('likeButton');
const dislikeButton = document.getElementById('dislikeButton');
const likeCount = document.getElementById('likeCount');
const dislikeCount = document.getElementById('dislikeCount');
const commentText = document.getElementById('commentText');
const submitComment = document.getElementById('submitComment');
const commentsContainer = document.getElementById('comments');
let isPlaying = false;
let updateInterval;
video.addEventListener('loadedmetadata', () => {
const aspectRatio = video.videoWidth / video.videoHeight;
canvas.width = canvas.clientWidth;
canvas.height = canvas.clientWidth / aspectRatio;
});
function drawFrame() {
context.drawImage(video, 0, 0, canvas.width, canvas.height);
}
function updateProgressBar() {
const percent = (video.currentTime / video.duration) * 100;
progress.style.width = percent + '%';
}
playPauseButton.addEventListener('click', () => {
if (isPlaying) {
video.pause();
playPauseButton.innerHTML = '►'; // Play button
clearInterval(updateInterval);
} else {
video.play();
playPauseButton.innerHTML = '❚❚'; // Pause button
updateInterval = setInterval(drawFrame, 1000 / 30); // Update at 30fps
}
isPlaying = !isPlaying;
});
video.addEventListener('timeupdate', updateProgressBar);
progressBar.addEventListener('click', (e) => {
const rect = progressBar.getBoundingClientRect();
const x = e.clientX - rect.left;
const percent = (x / progressBar.offsetWidth) * 100;
progress.style.width = percent + '%';
video.currentTime = (percent / 100) * video.duration;
});
volumeControl.addEventListener('click', (e) => {
const rect = volumeControl.getBoundingClientRect();
const x = e.clientX - rect.left;
const percent = x / volumeControl.offsetWidth;
video.volume = percent;
updateVolumeDisplay();
});
function updateVolumeDisplay() {
volumeProgress.style.width = (video.volume * 100) + '%';
}
updateVolumeDisplay(); // Initialize volume display
likeButton.addEventListener('click', () => {
updateFeedback('like');
});
dislikeButton.addEventListener('click', () => {
updateFeedback('dislike');
});
submitComment.addEventListener('click', () => {
const comment = commentText.value.trim();
if (comment) {
updateFeedback('comment', comment);
commentText.value = '';
displayComment(comment);
}
});
function updateFeedback(type, comment = '') {
const xhr = new XMLHttpRequest();
xhr.open('POST', 'update_feedback.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = () => {
if (xhr.status === 200) {
const response = JSON.parse(xhr.responseText);
likeCount.textContent = response.likes;
dislikeCount.textContent = response.dislikes;
}
};
xhr.send(`type=${type}&file=<?php echo urlencode($videoFile); ?>&comment=${encodeURIComponent(comment)}`);
}
function displayComment(comment) {
const commentElement = document.createElement('div');
commentElement.classList.add('comment');
commentElement.textContent = comment;
commentsContainer.appendChild(commentElement);
}
</script>