使用AVAudioPlayer播放来自互联网的音频 [英] play audio from internet using AVAudioPlayer

查看:98
本文介绍了使用AVAudioPlayer播放来自互联网的音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实施AVAudioPlayer播放音频,并且在播放本地存储在PC中的文件时效果非常好。

I am implementing AVAudioPlayer to play audio and it works perfectly well while playing files locally stored in the PC.

但是当我通过互联网提供某些音频文件的网址时,它很遗憾地失败了。
这是代码的样子:

But when i give the url of some audio file over the internet, it fails sadly. Here's what the code looks like:

NSString *url = [[NSString alloc] init];  
url = @"http://files.website.net/audio/files/audioFile.mp3";  
NSURL *fileURL = [[NSURL alloc] initWithString: url];  
AVAudioPlayer *newPlayer =[[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error: nil];

有人可以指出问题,可以做些什么?

谢谢!

Could anybody please point out the problem and what could be done?
Thanks!

推荐答案

我在AVAudioPlayer上尝试了其他方法initWithData而不是initWithContentsOfURL。首先尝试将MP3文件导入NSData,然后播放此数据。

I tried other method initWithData on AVAudioPlayer instead of initWithContentsOfURL. First try to get MP3 file into NSData and then play this data.

查看我的代码这里

这篇关于使用AVAudioPlayer播放来自互联网的音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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