1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-22 17:37:38 +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

View File

@@ -30,6 +30,12 @@ local function pcm_decoder(chunk)
return buffer
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 = ...
if cmd == "stop" then
@@ -97,6 +103,10 @@ elseif cmd == "play" then
handle.read(4)
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
print("Playing " .. file)