<?php
// Diagnostic tool to test direct video playback
require_once 'config/database.php';
require_once 'includes/functions.php';
?>
<!DOCTYPE html>
<html>
<head>
    <title>Video Test Diagnostic</title>
    <script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="p-8">
    <h1 class="text-3xl font-bold mb-8">Video Playback Diagnostic Tool</h1>
    
    <?php
    // List videos from directories
    $videoDirs = ['videos/', 'uploads/videos/'];
    foreach ($videoDirs as $dir) {
        if (is_dir($dir)) {
            echo "<h2 class='text-2xl mb-4'>Videos in $dir</h2>";
            $videos = glob($dir . '*.{mp4,webm,ogg,avi,mov,wmv}', GLOB_BRACE);
            if ($videos) {
                foreach ($videos as $video) {
                    $relPath = str_replace('c:/xampp/htdocs/lms/', '', $video);
                    $absUrl = '/lms/' . $relPath;
                    echo "<div class='mb-6 p-4 bg-gray-100 rounded-lg'>";
                    echo "<p><strong>File:</strong> $relPath</p>";
                    echo "<p><strong>Direct URL:</strong> <a href='$absUrl' target='_blank' class='text-blue-600 hover:underline'>$absUrl</a></p>";
                    echo "<video controls class='w-full max-w-2xl mt-2' preload='metadata'>";
                    echo "<source src='$absUrl' type='video/mp4'>";
                    echo 'Your browser does not support video.';
                    echo '</video>';
                    echo "<div class='mt-2 p-2 bg-yellow-100 text-sm'>Console (F12): Check for errors</div>";
                    echo "</div>";
                }
            } else {
                echo "<p>No videos found in $dir</p>";
            }
        }
    }
    ?>
    
    <div class='mt-8 p-6 bg-blue-50 rounded-lg'>
        <h3 class='font-bold mb-2'>Next Steps:</h3>
        <ol class='list-decimal ml-6 space-y-1'>
            <li>Test videos above. Note any that don't play.</li>
            <li>Open F12 Console/Network tab while playing.</li>
            <li>Check http://localhost/lms/test-video.php</li>
            <li>Report errors back for learn.php fixes.</li>
        </ol>
    </div>
</body>
</html>
