1. --!movie
  2. --!encoding=utf-8
  3.  
  4. global $
  5.  
  6. global gCh
  7. global gSize
  8. global gPos
  9.  
  10. ----------------------------------------
  11. -- Asynchronous or non-blocking mode:
  12. -- Header callback receives http result header data while download still running
  13. ----------------------------------------
  14. on startMovie
  15.     _player.debugPlaybackEnabled = 1
  16.  
  17.     -- libs
  18.     $.import("curl")
  19.  
  20.     gCh = $.curl.init() -- important for async mode: make CURL handle persistant!
  21.  
  22.     -- specify options
  23.     gCh.setOption($.curl.CURLOPT.URL, "http://valentin.dasdeck.com/xtras/curl_xtra/.test/test.mp3")
  24.  
  25.     gCh.setHeaderCallback(#slotCurlHeaders)
  26.  
  27.     -- returnMode: 0=return error code (=default), 1=return data, 2=return chunks immediately
  28.     $.curl.execAsyncDetached(gCh, #slotCurlResult, _movie, 2)
  29.  
  30.     gSize = 0
  31.     gPos = 0
  32. end
  33.  
  34. ----------------------------------------
  35. -- @callback
  36. ----------------------------------------
  37. on slotCurlHeaders (res)
  38.     -- Parse headers, extract size
  39.     headers = $.curl.parseHeaders(res.readRawString(res.length))
  40.     gSize = integer(headers["Content-Length"])
  41.     if voidP(gSize) then
  42.         put "ERROR: Could't determine download size! Aborting."
  43.         gCh = VOID
  44.         exit
  45.     else
  46.         put "Header data received, expected download size is" && gSize
  47.     end if
  48. end
  49.  
  50. ----------------------------------------
  51. -- @callback
  52. ----------------------------------------
  53. on slotCurlResult (res)
  54.     if ilk(res)=#bytearray then
  55.         gPos = gPos + res.length
  56.         if gSize>0 then
  57.             put (gPos*100)/gSize && "%"
  58.         end if
  59.     else
  60.         put "DOWNLOAD FINISCHED"
  61.         put "ERROR:" && curl_error(res)
  62. --      put "SPEED_DOWNLOAD:" && gCh.getInfo($.curl.CURLINFO.SPEED_DOWNLOAD)
  63. --      put "TOTAL_TIME:" && gCh.getInfo($.curl.CURLINFO.TOTAL_TIME)
  64.     end if
  65. end
  66.  
[raw code]