--!movie
--!encoding=utf-8
global $
global gCh
global gSize
global gPos
----------------------------------------
-- Asynchronous or non-blocking mode:
-- Header callback receives http result header data while download still running
----------------------------------------
on startMovie
_player.debugPlaybackEnabled = 1
-- libs
$.import("curl")
gCh = $.curl.init() -- important for async mode: make CURL handle persistant!
-- specify options
gCh.setOption($.curl.CURLOPT.URL, "http://valentin.dasdeck.com/xtras/curl_xtra/.test/test.mp3")
gCh.setHeaderCallback(#slotCurlHeaders)
-- returnMode: 0=return error code (=default), 1=return data, 2=return chunks immediately
$.curl.execAsyncDetached(gCh, #slotCurlResult, _movie, 2)
gSize = 0
gPos = 0
end
----------------------------------------
-- @callback
----------------------------------------
on slotCurlHeaders (res)
-- Parse headers, extract size
headers = $.curl.parseHeaders(res.readRawString(res.length))
gSize = integer(headers["Content-Length"])
if voidP(gSize) then
put "ERROR: Could't determine download size! Aborting."
gCh = VOID
exit
else
put "Header data received, expected download size is" && gSize
end if
end
----------------------------------------
-- @callback
----------------------------------------
on slotCurlResult (res)
if ilk(res)=#bytearray then
gPos = gPos + res.length
if gSize>0 then
put (gPos*100)/gSize && "%"
end if
else
put "DOWNLOAD FINISCHED"
put "ERROR:" && curl_error(res)
-- put "SPEED_DOWNLOAD:" && gCh.getInfo($.curl.CURLINFO.SPEED_DOWNLOAD)
-- put "TOTAL_TIME:" && gCh.getInfo($.curl.CURLINFO.TOTAL_TIME)
end if
end