Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 4d0ec0e

Browse files
resolved #90
1 parent f9c0f09 commit 4d0ec0e

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

client/lib/youcubeapi.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ function Speaker.new(speaker)
293293

294294
function self:validate()
295295
if not decoder then
296-
error("This ComputerCraft version dos not support DFPWM")
296+
return "This ComputerCraft version dos not support DFPWM"
297297
end
298298
end
299299

@@ -329,12 +329,14 @@ function Tape.new(tape)
329329

330330
function self:validate()
331331
if not self.tape.isReady() then
332-
error("You need to insert a tape")
332+
return "You need to insert a tape"
333333
end
334334
end
335335

336336
function self:setVolume(volume)
337-
self.tape.setVolume(volume)
337+
if volume then
338+
self.tape.setVolume(volume)
339+
end
338340
end
339341

340342
function self:play(chunk)
@@ -590,7 +592,7 @@ return {
590592
--- "Metadata" - [YouCube API](https://commandcracker.github.io/YouCube/) Version
591593
_API_VERSION = "0.0.0-poc.1.0.0",
592594
--- "Metadata" - Library Version
593-
_VERSION = "0.0.0-poc.1.1.0",
595+
_VERSION = "0.0.0-poc.1.2.0",
594596
--- "Metadata" - Description
595597
_DESCRIPTION = "Library for accessing YouCub's API",
596598
--- "Metadata" - Homepage / Url

client/youcube.lua

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Github Repository: https://github.com/Commandcracker/YouCube
77
License: GPL-3.0
88
]]
99

10-
local _VERSION = "0.0.0-poc.0.4.0"
10+
local _VERSION = "0.0.0-poc.0.5.0"
1111

1212
-- Libraries - OpenLibrarieLoader v1.0.0 --
1313

@@ -161,16 +161,30 @@ local youcubeapi = libs.youcubeapi.API.new()
161161

162162
local audiodevices = {}
163163

164-
if #speakers == 0 then
165-
for _, tape in pairs(tapes) do
166-
table.insert(audiodevices, libs.youcubeapi.Tape.new(tape))
167-
end
168-
else
169-
for _, speaker in pairs(speakers) do
170-
table.insert(audiodevices, libs.youcubeapi.Speaker.new(speaker))
164+
for _, speaker in pairs(speakers) do
165+
table.insert(audiodevices, libs.youcubeapi.Speaker.new(speaker))
166+
end
167+
168+
for _, tape in pairs(tapes) do
169+
table.insert(audiodevices, libs.youcubeapi.Tape.new(tape))
170+
end
171+
172+
local last_error
173+
local valid_audiodevices = {}
174+
175+
for i, audiodevice in pairs(audiodevices) do
176+
local _error = audiodevice:validate()
177+
if _error ~= nil then
178+
last_error = _error
179+
else
180+
table.insert(valid_audiodevices, audiodevice)
171181
end
172182
end
173183

184+
if #valid_audiodevices == 0 then
185+
error(last_error)
186+
end
187+
174188
-- update check --
175189

176190
local function get_versions()
@@ -283,7 +297,7 @@ local function update_checker()
283297
end
284298

285299
local function play_audio(buffer, title)
286-
for _, audiodevice in pairs(audiodevices) do
300+
for _, audiodevice in pairs(valid_audiodevices) do
287301
audiodevice:reset()
288302
audiodevice:setLabel(title)
289303
audiodevice:setVolume(args.volume)
@@ -299,7 +313,7 @@ local function play_audio(buffer, title)
299313

300314
if chunk == "" then
301315
local play_functions = {}
302-
for _, audiodevice in pairs(audiodevices) do
316+
for _, audiodevice in pairs(valid_audiodevices) do
303317
table.insert(play_functions, function()
304318
audiodevice:play()
305319
end)
@@ -310,7 +324,7 @@ local function play_audio(buffer, title)
310324
end
311325

312326
local write_functions = {}
313-
for _, audiodevice in pairs(audiodevices) do
327+
for _, audiodevice in pairs(valid_audiodevices) do
314328
table.insert(write_functions, function()
315329
audiodevice:write(chunk)
316330
end)
@@ -515,9 +529,6 @@ local function play_playlist(playlist)
515529
end
516530

517531
local function main()
518-
for _, audiodevice in pairs(audiodevices) do
519-
audiodevice:validate()
520-
end
521532
youcubeapi:detect_bestest_server(args.server, args.verbose)
522533
pcall(update_checker)
523534

versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"version": "0.0.0-poc.0.4.0",
1010
"libraries": {
1111
"youcubeapi": {
12-
"version": "0.0.0-poc.1.1.0"
12+
"version": "0.0.0-poc.1.2.0"
1313
},
1414
"numberformatter": {
1515
"version": "1.1.0"

0 commit comments

Comments
 (0)