1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-03-27 13:56:58 +00:00

Detect common audio containers in "speaker"

Trying to play a non-DFPWM (or WAV) file will generate terrible noise,
which in turns generates confused users. Instead, fail to play the audio
file and redirect them to the docs.
This commit is contained in:
Jonathan Coates 2023-03-29 09:51:09 +01:00
parent f93a33aa5e
commit dbd47be432
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06

View File

@ -30,6 +30,12 @@ local function pcm_decoder(chunk)
return buffer return buffer
end end
local function report_invalid_format(format)
printError(("The speaker cannot play %s files."):format(format))
local pp = require "cc.pretty"
pp.print("Run '" .. pp.text("help speaker", colours.lightGrey) .. "' for information on supported formats.")
end
local cmd = ... local cmd = ...
if cmd == "stop" then if cmd == "stop" then
@ -97,6 +103,10 @@ elseif cmd == "play" then
handle.read(4) handle.read(4)
start = nil start = nil
-- Detect several other common audio files.
elseif start == "OggS" then return report_invalid_format("Ogg")
elseif start == "fLaC" then return report_invalid_format("FLAC")
elseif start:sub(1, 3) == "ID3" then return report_invalid_format("MP3")
end end
print("Playing " .. file) print("Playing " .. file)