iOS Objective-C / Swift下载时读取文件 [英] iOS Objective-C/Swift read file while downloading

查看:130
本文介绍了iOS Objective-C / Swift下载时读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在下载播放音频文件,是否可能在iOS中?

I'm trying to play an audio file while it's downloading, is that possible in iOS?

我知道我可以获取文件的位置after通过以下方式下载:

I know I can get the location of the file "after" it's downloaded through:

(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location

但是,当我们还在下载的时候,我需要阅读/播放。

But I need to read/play it while it's still downloading.

更新
我原来的问题是:
我需要在右耳机或左耳机上播放流式音频文件。 AVAudioPlayer中已经有方法setPan,但AVAudioPlayer不能与流数据完美配合。另一方面,AVPlayer使用流数据完美,但不允许setPan。

Update My original problem is: I need to play a streamable audio file in either right or left headphones. There's already method setPan in AVAudioPlayer, but AVAudioPlayer does not work perfectly with streaming data. On the other hand, AVPlayer works perfect with streaming data, but it does not allow to "setPan".

我的想法是开始下载音频文件并传递给AVAudioPlayer并调用setPan,但在下载文件时无法访问该文件。而且我仍然不确定AVAudioPlayer是否会在播放文件时附加添加到文件中的新下载的数据。

My idea was to start downloading the audio file and pass it to AVAudioPlayer and call "setPan", but i can't access the file while it's being downloaded. And I'm still not sure if AVAudioPlayer will append the new downloaded data that is added to the file, while the file is playing.

推荐答案

直接使用

AVPlayer *anAudioStreamer = [[AVPlayer alloc] initWithURL:[NSURL URLWithString:@"http://my.url.com/my.mp3"]];
[anAudioStreamer play];

这篇关于iOS Objective-C / Swift下载时读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆