1. --!movie
  2. --!encoding=utf-8
  3.  
  4. global $
  5.  
  6. global gCh
  7.  
  8. ----------------------------------------
  9. -- Download a file with http get (asynchronous/non-blocking mode)
  10. -- Show progress info
  11. ----------------------------------------
  12. on startMovie
  13.     _player.debugPlaybackEnabled = 1
  14.  
  15.     -- libs
  16.     $.import("curl")
  17.  
  18.     -- config
  19.     tUrl = "http://valentin.dasdeck.com/xtras/curl_xtra/.test/test.mp3"
  20.     tFilename = $.PATH & "download_progress.mp3"
  21.  
  22.     -- start download
  23.     gCh = $.curl.init()
  24.  
  25.     gCh.setOption($.curl.CURLOPT.URL, tUrl)
  26.     gCh.setOption($.curl.CURLOPT.NOPROGRESS, 0)
  27.  
  28.     gCh.setDestinationFile(tFilename)
  29.     gCh.setProgressCallback(#slotCurlProgress)
  30.  
  31.     -- returnMode: 0=return error code (=default), 1=return data, 2=return chunks immediately
  32.     -- => has to be 0 (or void) to download as file!
  33.     $.curl.execAsyncDetached(gCh, #slotCurlResult)
  34.  
  35.     gPos = 0
  36.     put "0 %"
  37. end
  38.  
  39. ----------------------------------------
  40. -- @callback
  41. ----------------------------------------
  42. on slotCurlResult (res)
  43.     put "ERROR:" && curl_error(res)
  44. --  put "SPEED_UPLOAD:" && gCh.getInfo($.curl.CURLINFO.SPEED_UPLOAD)
  45. --  put "TOTAL_TIME:" && gCh.getInfo($.curl.CURLINFO.TOTAL_TIME)
  46.     gCh = VOID
  47. end
  48.  
  49. ----------------------------------------
  50. -- @callback
  51. ----------------------------------------
  52. on slotCurlProgress (dltotal, dlnow, ultotal, ulnow)
  53.     --put dltotal, dlnow, ultotal, ulnow
  54.     if dltotal>0 then
  55.         put (dlnow*100/dltotal) && "%"
  56.     end if
  57. end
  58.  
[raw code]