<bdo id='zGOLY'></bdo><ul id='zGOLY'></ul>

    1. <i id='zGOLY'><tr id='zGOLY'><dt id='zGOLY'><q id='zGOLY'><span id='zGOLY'><b id='zGOLY'><form id='zGOLY'><ins id='zGOLY'></ins><ul id='zGOLY'></ul><sub id='zGOLY'></sub></form><legend id='zGOLY'></legend><bdo id='zGOLY'><pre id='zGOLY'><center id='zGOLY'></center></pre></bdo></b><th id='zGOLY'></th></span></q></dt></tr></i><div id='zGOLY'><tfoot id='zGOLY'></tfoot><dl id='zGOLY'><fieldset id='zGOLY'></fieldset></dl></div>
        <tfoot id='zGOLY'></tfoot>
        <legend id='zGOLY'><style id='zGOLY'><dir id='zGOLY'><q id='zGOLY'></q></dir></style></legend>

        <small id='zGOLY'></small><noframes id='zGOLY'>

        从服务器下载音乐文件并保存在我的应用程序中

        时间:2023-10-22
          <tbody id='n51VF'></tbody>

        <small id='n51VF'></small><noframes id='n51VF'>

        • <legend id='n51VF'><style id='n51VF'><dir id='n51VF'><q id='n51VF'></q></dir></style></legend>

          • <bdo id='n51VF'></bdo><ul id='n51VF'></ul>
            <i id='n51VF'><tr id='n51VF'><dt id='n51VF'><q id='n51VF'><span id='n51VF'><b id='n51VF'><form id='n51VF'><ins id='n51VF'></ins><ul id='n51VF'></ul><sub id='n51VF'></sub></form><legend id='n51VF'></legend><bdo id='n51VF'><pre id='n51VF'><center id='n51VF'></center></pre></bdo></b><th id='n51VF'></th></span></q></dt></tr></i><div id='n51VF'><tfoot id='n51VF'></tfoot><dl id='n51VF'><fieldset id='n51VF'></fieldset></dl></div>

                <tfoot id='n51VF'></tfoot>
                  本文介绍了从服务器下载音乐文件并保存在我的应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要从服务器下载一个 .mp3 音频文件以保存在我的应用程序中,无需下载即可播放,就像下面的屏幕截图一样,带有下载进度条(我在 App Store 中找到了这个).任何人都可以通过源代码帮助我在我的应用程序中执行此操作吗?任何帮助将不胜感激!提前致谢!

                  I need to download an .mp3 audio file from a server to save in my app and play it without downloading, exactly like the screenshot below, with a progress bar for the download (I found this in the App Store). Can anyone help me to do this in my app, with source code? Any help will be appreciated! Thanks in advance!

                  我使用了 NSURLConnection,但它对我不起作用.

                  I used NSURLConnection but it does not really work for me.

                  这是我正在尝试做的屏幕截图.

                  Here is the screenshot of what I am trying to do.

                  推荐答案

                  这个问题讨论了你在寻找什么

                  This questions discusses what you're looking for

                  如果你想下载一个文件然后播放它,你需要做的是:

                  If you want to download a file THEN play it, what you need to do is:

                  使用 NSURLConnection 将文件下载到磁盘 - this 链接讨论了保存大文件(当我不需要它们时,我不会在内存中保留 2-5mb,即使我认为它会可能工作).

                  use an NSURLConnection to download the file to the disk - this link discusses saving large files (i wouldn't keep 2-5mb's in the memory when i don't need them even thought it will probably work).

                  ,比 AVAudioPlayer 播放它 - 检查 this 出去.

                  , than an AVAudioPlayer to play it - check this out.

                  编辑 2:

                  对于取消按钮,它实际上应该只调用 [NSURLConnection cancel] 方法并执行完成下载类所需的任何其他操作...

                  For the cancel button, it should practically just call the [NSURLConnection cancel] method and do whatever other finishing up your download class is gonna need...

                  对于进度条,在 NSURLConnectionDelegate 方法 didReceiveResponse 中,您获取 NSURLResponse,将其转换为 NSHTTPURLResponse,并使用 expectedContentLength 方法.

                  For the progress bar, in the NSURLConnectionDelegate method didReceiveResponse, you take the NSURLResponse, cast it to a NSHTTPURLResponse, and retrieve the size of the file you're downloading using the expectedContentLength method.

                  然后在每次调用 NSURLConnection:didRecieveData 方法时,使用 [数据长度] 方法计算传入字节数,然后除以 expectedContentLength 来自上一个 URL响应,这是代表您传递给进度视图的进度的浮点数 progress 属性

                  And then in each call to the NSURLConnection:didRecieveData method you count the incoming bytes using [data length] method, divide it by the expectedContentLength from the previous URL response and that's the float the represents your progress that you pass to the progress view's progress property

                  这篇关于从服务器下载音乐文件并保存在我的应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Iphone 3Gs 和 Iphone 3 下一篇:如何在 iOS 上将 UILabel 中的文本基线与不同的字体大小对齐?

                  相关文章

                  <i id='pSIQa'><tr id='pSIQa'><dt id='pSIQa'><q id='pSIQa'><span id='pSIQa'><b id='pSIQa'><form id='pSIQa'><ins id='pSIQa'></ins><ul id='pSIQa'></ul><sub id='pSIQa'></sub></form><legend id='pSIQa'></legend><bdo id='pSIQa'><pre id='pSIQa'><center id='pSIQa'></center></pre></bdo></b><th id='pSIQa'></th></span></q></dt></tr></i><div id='pSIQa'><tfoot id='pSIQa'></tfoot><dl id='pSIQa'><fieldset id='pSIQa'></fieldset></dl></div>

                • <small id='pSIQa'></small><noframes id='pSIQa'>

                    1. <tfoot id='pSIQa'></tfoot>
                    2. <legend id='pSIQa'><style id='pSIQa'><dir id='pSIQa'><q id='pSIQa'></q></dir></style></legend>

                      • <bdo id='pSIQa'></bdo><ul id='pSIQa'></ul>