local video player

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Local Video Player</title>
  <style>
    body {
      background: #121212;
      color: #fff;
      font-family: Arial, sans-serif;
      text-align: center;
      padding: 20px;
    }

    h2 {
      color: #00ccff;
    }

    input[type="file"] {
      margin-bottom: 15px;
    }

    video {
      width: 100%;
      max-width: 600px;
      margin-top: 10px;
      border: 2px solid #00ccff;
      border-radius: 10px;
    }

    .controls {
      margin-top: 10px;
      display: flex;
      justify-content: center;
      flex-wrap: wrap;
      gap: 10px;
      align-items: center;
    }

    button {
      padding: 6px 12px;
      background: #00ccff;
      border: none;
      border-radius: 5px;
      color: white;
      cursor: pointer;
    }

    button:hover {
      background: #009ecc;
    }

    input[type="range"] {
      width: 100px;
    }

    .time {
      font-family: monospace;
    }
  </style>
</head>
<body>

  <h2>🎬 Local Video Player</h2>

  <!-- File picker -->
  <input type="file" id="fileInput" accept="video/*">

  <!-- Video element -->
  <video id="video" controls></video>

  <!-- Custom controls -->
  <div class="controls">
    <button id="playPause">▶️ Play</button>
    <button onclick="video.currentTime -= 10">⏪ -10s</button>
    <button onclick="video.currentTime += 10">⏩ +10s</button>
    <input type="range" id="volume" min="0" max="1" step="0.05" value="1">
    <span class="time" id="timeDisplay">00:00 / 00:00</span>
    <button id="fullscreen">🔳 Fullscreen</button>
  </div>

  <script>
    const video = document.getElementById('video');
    const fileInput = document.getElementById('fileInput');
    const playPause = document.getElementById('playPause');
    const volume = document.getElementById('volume');
    const timeDisplay = document.getElementById('timeDisplay');
    const fullscreenBtn = document.getElementById('fullscreen');

    // Load video from local file
    fileInput.addEventListener('change', () => {
      const file = fileInput.files[0];
      if (file) {
        const url = URL.createObjectURL(file);
        video.src = url;
        video.load();
        video.play();
        playPause.textContent = '⏸️ Pause';
      }
    });

    // Play / Pause toggle
    playPause.addEventListener('click', () => {
      if (video.paused) {
        video.play();
        playPause.textContent = '⏸️ Pause';
      } else {
        video.pause();
        playPause.textContent = '▶️ Play';
      }
    });

    // Volume
    volume.addEventListener('input', () => {
      video.volume = volume.value;
    });

    // Fullscreen
    fullscreenBtn.addEventListener('click', () => {
      if (video.requestFullscreen) video.requestFullscreen();
      else if (video.webkitRequestFullscreen) video.webkitRequestFullscreen();
      else if (video.msRequestFullscreen) video.msRequestFullscreen();
    });

    // Time display update
    function formatTime(t) {
      const m = Math.floor(t / 60);
      const s = Math.floor(t % 60);
      return `${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`;
    }

    function updateTime() {
      timeDisplay.textContent = `${formatTime(video.currentTime)} / ${formatTime(video.duration || 0)}`;
    }

    video.addEventListener('timeupdate', updateTime);
    video.addEventListener('loadedmetadata', updateTime);
  </script>

</body>
</html>

Comments