2014-02-15 169 views
1

我发现了很多关于SO的相关问题,或者因为我很新,或者因为它不完全适合我的问题,我找不到成功的方法。如何流式传输MP3文件(iOS)

因此,所有我想要做的是打直接在iOS设备(iPhone在我的情况)对存储在exernal服务器上的音频文件

我曾尝试在网上型动物的解决方案,而这正是我到现在为止。

NSString* resourcePath = @"http://www.chiptape.com/chiptape/sounds/medium/laugh.mp3"; //your url 
NSURL *url = [[NSURL alloc]initWithString:resourcePath]; 

NSError *error; 

audioPlayer = [[AVAudioPlayer alloc] initWithURL:url error:&error]; 

audioPlayer.delegate = self; 
[url release]; 

[audioPlayer prepareToPlay]; 
[audioPlayer play]; 

编译器告诉我这个错误:

No visible @interface for 'AVAudioPlayer' declares the selector 'initWithURL:error:'

我不知道在所有关于我的代码,想你的人知道我已经开始的iOS昨天编码,所以这不是不可能的我错过了很明显的东西,教程/帖子没有提到它。

此外,我已经导入库AVFoundation并将其导入到我的.h文件中。 我还宣称这对我的.h文件

AVAudioPlayer *audioPlayer; 

我希望有一个简单的方法来传输音频文件,在iOS上为提供的Android/java的

谢谢你,如果你需要更多的细节发表评论,我会更新我的帖子。

+0

我想'DOUAudioStreamer'可能是很长的路要走。这是一个更新的iOS开源音频流媒体https://github.com/douban/DOUAudioStreamer – jbouaziz

回答

0

我正在最近使用它。

AVAudioPlayer无法使用音频流。事实上,这并不是一个简单的方法。

您需要学习一些Core Audio的东西,获取媒体的原始数据,在audioQueue(audioToolBox框架)中播放它们。实时音频处理不是一件简单的工作,它充满了c级api和许多肮脏的工作,不要急于求成:)

检查出书Learning Core Audio和这个开源audio streamer

让我知道你是否需要更多帮助。

+0

我会检查它,并且这个开源音频流媒体是美妙的。 谢谢,我会让你知道它是怎么回事 – user3312399

0

试试这个:

NSString* resourcePath = @"http://www.chiptape.com/chiptape/sounds/medium/laugh.mp3"; //your url 
NSURL *audioURL = [NSURL URLWithString:resourcePath]; 
AVAudioPlayer *audioPlayer = [[[AVAudioPlayer alloc] initWithContentsOfURL: audioURL error:&error]autorelease];  
[audioPlayer play];