简体   繁体   English

恢复从iOS和Android上使用Corona sdk编写的移动应用程序下载大文件的下载

[英]Resume a download of a large file from a mobile app written using corona sdk on ios and android

I need to download large audio files from a web server from within a corona sdk app, and have been looking at using network.download() or possibly network.request() for this purpose. 我需要从电晕sdk应用程序中从Web服务器下载大型音频文件,并且一直在考虑使用network.download()或可能使用network.request()来实现此目的。

Because much of the user base will be in areas that have poor or intermittent network coverage, I would like to improve robustness of the download process by allowing for resuming download from where it left off if the network drops out. 因为大部分用户群将位于网络覆盖范围较差或间歇的区域,所以我想通过允许在网络中断时从中断的地方继续下载来提高下载过程的稳定性。 From the documentation neither network.download or network.request functions seem to support this directly, but is there a way that I can use either of these functions to achieve what I'm looking for? 从文档中,network.download或network.request函数似乎都不直接支持此功能,但是有没有办法我可以使用这两个函数来实现所需的功能呢? If not, is there another technique I can use? 如果没有,我可以使用另一种技术吗?

My app will eventually be for both iOS and Android , but for now I am developing the iOS version first. 我的应用最终将同时适用iOS和Android ,但现在我首先开发iOS版本。 Therefore, I am ok with having to use a different solution for each platform if there is not an easy solution that covers both platforms. 因此,如果没有一个涵盖两个平台的简单解决方案,我可以为每个平台使用不同的解决方案。 However, I would prefer not to have to use native code if possible as I don't currently have an Enterprise subscription for Corona. 但是,如果可能的话,我不希望不必使用本机代码,因为我目前没有针对Corona的企业版订阅。

I don't think you can do this using Corona without native plugins. 我不认为没有本地插件就可以使用Corona做到这一点。

One way to go around this problem is to split the large files in smaller ones, and I don't mean creating multiple audio files just splitting the large audio files in smaller files. 解决此问题的一种方法是将大文件拆分为较小的文件,我并不是说要创建多个音频文件,而只是将大音频文件拆分为较小的文件。

Then you can download one chunk at a time and when one fails, by getting an error in the handler or waiting a reasonable timeout and then checking to see if the file is present in the file system, you can start downloading it again. 然后,您可以一次下载一个块,如果一个块失败,则可以通过在处理程序中获取错误或等待合理的超时,然后检查文件系统中是否存在该文件来进行重新下载。

After all chunks are download you can recreate the large file by using the ltn library. 在下载所有块之后,您可以使用ltn库重新创建大文件。

You can read some more about the ltn12 library here and I think you need to take a close look to the Pumps method. 您可以在此处阅读有关ltn12库的更多信息,我认为您需要仔细研究Pumps方法。

On your server-side, create a simple program that splits an audio file in multiple sub-files of the max size you would like to specify. 在服务器端,创建一个简单的程序,将音频文件拆分为您要指定的最大大小的多个子文件。 On your client-side, create a function that collides multiple chunks in one single audio files. 在您的客户端上,创建一个可在单个音频文件中碰撞多个块的函数。

For example if you would like to limit your file size to 1MB, create a server side program that splits any audio file above 1MB in chunks: a 4.5MB file would be split in part1 1MB, part2 1MB, part3 1MB, part4 1MB, part5 0.5MB. 例如,如果您想将文件大小限制为1MB,则创建一个服务器端程序,将大于1MB的任何音频文件拆分为多个块:将4.5MB文件拆分为part1 1MB,part2 1MB,part3 1MB,part4 1MB,part5 0.5MB。 Glue the chunks together in one single file in your lua code when you have fetched that with network.request. 当您使用network.request进行抓取时,将这些块粘合到lua代码的一个文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM