简体   繁体   English

如何流mp3文件(iOS)

[英]How to stream mp3 files (iOS)

I have found many related questions on SO, but or because I am very new, or because it doesn't exactly fit my problem, I can't find a way to succeed. 我在SO上找到了许多相关问题,但是或者因为我很新,或者因为它不完全适合我的问题,所以我找不到成功的方法。

So, all I would like to do is playing an audio file stored on an exernal server directly on the iOS device (iPhone in my case) 因此,我要做的就是直接在iOS设备(本机为iPhone)上播放存储在外部服务器上的音频文件

I have tried differents solution on the net, and this is what I get until now. 我已经在网上尝试了不同的解决方案,这是我到目前为止所得到的。

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];

The compiler show me this error: 编译器向我显示此错误:

No visible @interface for 'AVAudioPlayer' declares the selector 'initWithURL:error:' “ AVAudioPlayer”没有可见的@interface声明选择器“ initWithURL:error:”

I am not sure at all about my code, and would like your guys to know I have started iOS coding yesterday, so it's not impossible I'm missing something so obvious that tutorials/posts don't mention it. 我完全不确定我的代码,并且希望你们知道昨天我已经开始进行iOS编码,因此我很可能会丢失一些显而易见的东西,以至于教程/帖子中都没有提到它。

Also, I have imported the library AVFoundation and imported it on my .h file. 另外,我已经导入了AVFoundation库并将其导入到我的.h文件中。 I have also declared this on my .h file 我也在.h文件中声明了这一点

AVAudioPlayer *audioPlayer;

I hope there is an easy way to stream audio file on iOS as provide android/java 我希望有一种简单的方法可以在iOS上以提供android / java的方式流式传输音频文件

Thank you and if you need more details comment and I'll update my post. 谢谢,如果您需要更多详细信息,请发表评论,我将更新我的帖子。

I'm working with it recently. 我最近正在使用它。

AVAudioPlayer can't work with audio stream. AVAudioPlayer无法使用音频流。 In fact, there isn't an easy way to do that. 实际上,没有简单的方法可以做到这一点。

You need to learn some Core Audio things, get the raw data of media, play them in audioQueue (audioToolBox framework). 您需要学习一些Core Audio知识,获取媒体的原始数据,然后在audioQueue(audioToolBox框架)中播放它们。 Real-time audio processing is not a simple work, it's full of c-level api and so many dirty work, don't rush, have fun :) 实时音频处理不是一件容易的事,它充满了c级api和那么多肮脏的工作,请不要着急,玩得开心:)

Check out the book Learning Core Audio and this open-source audio streamer . 查看《 学习核心音频 》一书和此开源音频流媒体

Let me know if you need more help. 让我知道您是否需要更多帮助。

Try this: 尝试这个:

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];

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

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