从Lua中的URL加载音频文件

从Lua中的URL加载音频文件,lua,mp3,Lua,Mp3,我需要从Lua中的URL加载mp3文件 我试过这个,但不起作用 require "socket.http" local resp, stat, hdr = socket.http.request{ url = "https://www.dropbox.com/s/hfrdbncfgbsarou/hello.mp3?dl=1", } local audioFile = audio.loadSound(resp) audio.play(audioFile) 有什么想法吗?请求函数“

我需要从Lua中的URL加载mp3文件

我试过这个,但不起作用

require "socket.http"

local resp, stat, hdr = socket.http.request{
  url     = "https://www.dropbox.com/s/hfrdbncfgbsarou/hello.mp3?dl=1",
}

local audioFile = audio.loadSound(resp)
audio.play(audioFile)

有什么想法吗?

请求函数“过载”(用其他语言的术语)。如中所述,它有三个签名:

local responsebodystring, statusnumber, headertable, statusstring 
  = request( urlstring ) -- GET

local responsebodystring, statusnumber, headertable, statusstring 
  = request( urlstring, requestbodystring ) -- POST

local success, statusnumber, headertable, statusstring 
  = request( requestparametertable ) -- depends on parameters
有关详细信息,请参阅文档,特别是有关错误结果的信息

对于最后一种形式,Lua语法允许使用表构造函数而不是括号中的单个表参数调用函数。这就是您正在使用的形式和语法。但是,您错误地期望第一个返回值是响应主体。响应主体被传递给一个“sink”函数,该函数在请求参数表中有选择地指示,而您没有

尝试第一种形式:

local resp, stat, hdr 
  = socket.http.request("https://www.dropbox.com/s/hfrdbncfgbsarou/hello.mp3?dl=1")