<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Custom video player script
$videoFilePath = '/a/videos' . $_GET['video'];

// You can add security checks here to ensure only authorized users can access videos.

// Get the requested action (skip forward or skip backward)
$action = isset($_GET['action']) ? $_GET['action'] : '';

// Calculate the skip amount (1 minute in seconds)
$skipAmount = 60;

if ($action === 'forward') {
    // Skip 1 minute ahead
    header("Location: custom-player.php?video={$_GET['video']}&time=" . (time() + $skipAmount));
    exit;
} elseif ($action === 'backward') {
    // Skip 1 minute back
    header("Location: custom-player.php?video={$_GET['video']}&time=" . (time() - $skipAmount));
    exit;
}

// If no action is specified, serve the video
if (isset($_GET['time'])) {
    // If a specific time is requested, use it
    $startTime = $_GET['time'];
} else {
    // Otherwise, start from the beginning
    $startTime = 0;
}

header('Content-Type: video/mp4');
header('Content-Length: ' . (filesize($videoFilePath) - $startTime));

// Set the Content-Range header to start the video at the specified time
header("Content-Range: bytes {$startTime}-" . (filesize($videoFilePath) - 1) . '/' . filesize($videoFilePath));

// Open the file and seek to the specified time
$file = fopen($videoFilePath, 'rb');
fseek($file, $startTime);

// Stream the video from the specified time
while (!feof($file)) {
    echo fread($file, 8192);
}

fclose($file);
?>
