import React, { useState, useRef } from "react"; import shaka from "shaka-player"; // Import the Shaka Player library import { Helmet } from 'react-helmet'; function TestPlayer() { const [mpdUrl, setMpdUrl] = useState(""); const [kid, setKid] = useState(""); const [key, setKey] = useState(""); const videoRef = useRef(null); // Ref to the video element const handleSubmit = () => { if (mpdUrl && kid && key) { // Split the KIDs and Keys by new lines const kidsArray = kid.split("\n").map((k) => k.trim()); const keysArray = key.split("\n").map((k) => k.trim()); if (kidsArray.length !== keysArray.length) { console.error("The number of KIDs and Keys must be the same."); return; } // Initialize Shaka Player only when the submit button is pressed const player = new shaka.Player(videoRef.current); // Widevine DRM configuration with the provided KIDs and Keys const config = { drm: { clearKeys: {}, }, }; // Map KIDs to Keys kidsArray.forEach((kid, index) => { config.drm.clearKeys[kid] = keysArray[index]; }); console.log("Configuring player with the following DRM config:", config); player.configure(config); const manifestUri = mpdUrl; // Get the MPD URL from state player.load(manifestUri) .then(() => { console.log("Shaka Player loaded successfully."); // Start playback once the stream is loaded successfully videoRef.current.play(); }) .catch((error) => { console.error("Error loading the stream:", error); }); } }; return (
Test Player
setMpdUrl(e.target.value)} className="text-white bg-[rgba(0,0,0,0.2)] focus:outline-none rounded focus:shadow-sm focus:shadow-red-700/50 transition-all duration-300 ease-in-out p-2" />