mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-27 09:24:47 +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:
parent
f93a33aa5e
commit
dbd47be432
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user