评论

2 条评论

  • William Wong

    你查看Sample中的MediaFileDetailsFragment.kt文件中有关于下载的完整方法,你需要手动打开文件,写入,关闭文件。

    fun downloadFile(){
    val dirs: File = File(DiskUtil.getExternalCacheDirPath(ContextUtil.getContext(), mediaFileDir))
    if (!dirs.exists()) {
    dirs.mkdirs()
    }

    val filepath = DiskUtil.getExternalCacheDirPath(ContextUtil.getContext(), mediaFileDir + "/" + mediaFile?.fileName)
    val file: File = File(filepath)
    if (file.exists()) {
    file.delete()
    }
    val outputStream = FileOutputStream(file)
    val bos = BufferedOutputStream(outputStream)
    var beginTime = System.currentTimeMillis()
    mediaFile?.pullOriginalMediaFileFromCamera(0 , object :MediaFileDownloadListener {
    override fun onStart() {
    showProgress()
    }

    override fun onProgress(total: Long, current: Long) {
    updateProgress(current , total)
    }

    override fun onRealtimeDataUpdate(data: ByteArray, position: Long) {
    try {
    bos.write(data, 0, data.size)
    bos.flush()
    } catch (e: IOException) {
    LogUtils.e("MediaFile" , "write error" + e.message)
    }
    }

    override fun onFinish() {
    var spendTime = (System.currentTimeMillis() - beginTime)
    var speedBytePerMill : Float? = mediaFile?.fileSize?.div(spendTime.toFloat())
    var divs = 1000.div(1024 * 1024.toFloat());
    var speedKbPerSecond : Float?= speedBytePerMill?.times(divs)

    ToastUtils.showToast(getString(R.string.msg_download_compelete_tips) + "${speedKbPerSecond }Mbps"
    + getString(R.string.msg_download_save_tips) + "${filepath}" )
    hideProgress()
    try {
    outputStream.close()
    bos.close()
    } catch (error: IOException) {
    LogUtils.e("MediaFile" , "close error$error" )
    }
    }

    override fun onFailure(error: IDJIError?) {
    LogUtils.e("MediaFile" , "download error$error" )
    }

    })
    }
    0
    评论操作 固定链接
  • 揭小强

    看到了  谢谢

    0
    评论操作 固定链接

请先登录再写评论。