Spaces:
Configuration error
Configuration error
Download PostcardVideoPlayer.client.lua from arnaupq2/RobloxVideoRO: direct link, hf CLI and curl.
- Browser
- Download file 4.54 kB
-
https://huggingface.co/spaces/arnaupq2/RobloxVideoRO/resolve/main/PostcardVideoPlayer.client.lua
- Command line
-
hf download hf://spaces/arnaupq2/RobloxVideoRO/PostcardVideoPlayer.client.lua
-
curl -L -o PostcardVideoPlayer.client.lua https://huggingface.co/spaces/arnaupq2/RobloxVideoRO/resolve/main/PostcardVideoPlayer.client.lua
4.54 kB
| -- PostcardVideoPlayer.client.lua | |
| -- Colocar en: StarterPlayer > StarterPlayerScripts | |
| -- | |
| -- Cuando recibe el aviso del servidor (al tocar PanelPostcard), pide al | |
| -- servidor local (http://localhost:4000, definido en server.js) la info del | |
| -- video y sus frames, y los va pintando en un EditableImage a pantalla | |
| -- completa, frame a frame, respetando los fps del video. | |
| -- | |
| -- IMPORTANTE: | |
| -- * Hay que activar "Allow HTTP Requests" en Game Settings > Security. | |
| -- * Esto solo funciona probando en Roblox Studio (Play / Play Solo), porque | |
| -- "localhost" es tu propio ordenador, no llega a un juego ya publicado. | |
| -- * Requiere una versión de Roblox con soporte de EditableImage / Content. | |
| local HttpService = game:GetService("HttpService") | |
| local AssetService = game:GetService("AssetService") | |
| local ReplicatedStorage = game:GetService("ReplicatedStorage") | |
| local Players = game:GetService("Players") | |
| local UserInputService = game:GetService("UserInputService") | |
| local BASE_URL = "http://localhost:4000" | |
| local remoteEvent = ReplicatedStorage:WaitForChild("PlayPostcardVideoEvent") | |
| local player = Players.LocalPlayer | |
| local isPlaying = false | |
| local function buildGui() | |
| local screenGui = Instance.new("ScreenGui") | |
| screenGui.Name = "PostcardVideoGui" | |
| screenGui.IgnoreGuiInset = true | |
| screenGui.DisplayOrder = 999 | |
| screenGui.ResetOnSpawn = false | |
| screenGui.Enabled = false | |
| local background = Instance.new("Frame") | |
| background.Name = "Background" | |
| background.Size = UDim2.new(1, 0, 1, 0) | |
| background.Position = UDim2.new(0, 0, 0, 0) | |
| background.BackgroundColor3 = Color3.new(0, 0, 0) | |
| background.BorderSizePixel = 0 | |
| background.ZIndex = 1 | |
| background.Parent = screenGui | |
| local imageLabel = Instance.new("ImageLabel") | |
| imageLabel.Name = "VideoFrame" | |
| imageLabel.Size = UDim2.new(1, 0, 1, 0) | |
| imageLabel.Position = UDim2.new(0, 0, 0, 0) | |
| imageLabel.BackgroundTransparency = 1 | |
| imageLabel.ScaleType = Enum.ScaleType.Fit | |
| imageLabel.ZIndex = 2 | |
| imageLabel.Parent = background | |
| local closeButton = Instance.new("TextButton") | |
| closeButton.Name = "CloseButton" | |
| closeButton.Size = UDim2.new(0, 44, 0, 44) | |
| closeButton.Position = UDim2.new(1, -54, 0, 10) | |
| closeButton.BackgroundColor3 = Color3.fromRGB(30, 30, 30) | |
| closeButton.BackgroundTransparency = 0.3 | |
| closeButton.Text = "X" | |
| closeButton.TextColor3 = Color3.new(1, 1, 1) | |
| closeButton.TextScaled = true | |
| closeButton.Font = Enum.Font.GothamBold | |
| closeButton.ZIndex = 3 | |
| closeButton.Parent = background | |
| screenGui.Parent = player:WaitForChild("PlayerGui") | |
| return screenGui, imageLabel, closeButton | |
| end | |
| local screenGui, imageLabel, closeButton = buildGui() | |
| local function stopPlayback() | |
| isPlaying = false | |
| screenGui.Enabled = false | |
| end | |
| closeButton.MouseButton1Click:Connect(stopPlayback) | |
| UserInputService.InputBegan:Connect(function(input, processed) | |
| if processed then | |
| return | |
| end | |
| if input.KeyCode == Enum.KeyCode.Escape and screenGui.Enabled then | |
| stopPlayback() | |
| end | |
| end) | |
| local function httpGet(url) | |
| local ok, result = pcall(function() | |
| return HttpService:RequestAsync({ | |
| Url = url, | |
| Method = "GET", | |
| }) | |
| end) | |
| if not ok or not result or not result.Success then | |
| return nil | |
| end | |
| return result | |
| end | |
| local function playVideo() | |
| if isPlaying then | |
| return | |
| end | |
| local infoResponse = httpGet(BASE_URL .. "/video/info") | |
| if not infoResponse then | |
| warn("No se pudo conectar con el servidor de video en " .. BASE_URL .. " (¿está corriendo 'npm start' en la carpeta Uidevideo?)") | |
| return | |
| end | |
| local ok, info = pcall(function() | |
| return HttpService:JSONDecode(infoResponse.Body) | |
| end) | |
| if not ok or not info or not info.ready then | |
| warn("El servidor de video todavía no está listo (¿terminó de procesar video.mp4?)") | |
| return | |
| end | |
| local width = info.width | |
| local height = info.height | |
| local fps = info.fps | |
| local frameCount = info.frameCount | |
| local frameTime = 1 / fps | |
| local editableImage = AssetService:CreateEditableImage({ | |
| Size = Vector2.new(width, height), | |
| }) | |
| imageLabel.ImageContent = Content.fromObject(editableImage) | |
| isPlaying = true | |
| screenGui.Enabled = true | |
| for i = 0, frameCount - 1 do | |
| if not isPlaying then | |
| break | |
| end | |
| local frameResponse = httpGet(BASE_URL .. "/video/frame/" .. i) | |
| if frameResponse and isPlaying then | |
| local bytes = frameResponse.Body | |
| local buf = buffer.fromstring(bytes) | |
| editableImage:WritePixelsBuffer(Vector2.new(0, 0), Vector2.new(width, height), buf) | |
| end | |
| task.wait(frameTime) | |
| end | |
| if isPlaying then | |
| stopPlayback() | |
| end | |
| end | |
| remoteEvent.OnClientEvent:Connect(function() | |
| playVideo() | |
| end) | |