I am trying to load a .wav file using sys.load_resource, and for a reason i can’t figure out, it is giving me the above error. As i have been typing this out, i do realize that it could just be me trying to load an incompatible file type but if this is the case, it would be helpful if i could get some help as to what would be a better method or an alternative
any help would be greatly appreciated, thanks
sys.load_resource()
is for reading resources in our archive file (aka [custom resources](Working with files ))
Beware that loading files from any place isn’t a portable way for all the platforms.
As for loading directly from disc, you can use Lua’s io.*
module.
Then you can use the [sound.create_sound_data()](API reference (Resource) ) to add it to the engine.
Then set the sound [hash property](API reference (Resource) ), and you should be ready to play.
Here’s an example, albeit from streaming from Http:
local function http_result(self, _id, response, extra)
if response.status == 200 or response.status == 206 or response.status == 304 then
--pprint(response.headers)
pprint(response)
print("Playing web sound:", response.url)
local relative_path = self.filename
-- local range = response.headers['content-range'] -- content-range = "bytes 0-16383/103277"
-- local rstart, rend, filesize = parse_range(range)
-- Create the Defold resource, "partial" will enable the streaming mode
print("Creating resource", relative_path)
local hash = resource.create_sound_data(relative_path, { data = response.response, filesize = response.document_size, partial = true })
-- send "play_sound" to the component
play_sound(self, hash)
end
end
local function load_web_sound(base_url, relative_path)
local url = base_url .. "/" .. relative_path
local range_start = 0
local range_end = 16384-1
1 Like