ios - 我正在尝试使用 AVAudioPlayer 从服务器播放音频,但文件未播放

标签 ios audio avaudioplayer

我正在尝试制作一个在线音频播放器。但我无法使用 AVAudioPlayer 对象播放音频。请帮我。提前致谢。

这是我的音频播放器代码。 ================>>>

NSURL *url =[[NSURL alloc] initWithString:@"My Url"];

xPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
xPlayer.numberOfLoops = 0;
xPlayer.volume = 1.0f;

[xPlayer prepareToPlay];
[xPlayer play];

最佳答案

问:AVAudioPlayer 是否支持流式音频内容?

A:AVAudioPlayer 类不支持基于 HTTP URL 的流式音频。与 initWithContentsOfURL: 一起使用的 URL 必须是文件 URL (file://)。即本地路径。

来源:https://developer.apple.com/library/ios/qa/qa1634/_index.html

关于ios - 我正在尝试使用 AVAudioPlayer 从服务器播放音频,但文件未播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29390071/

相关文章:

ios - 如何使用自动布局更改标签位置

ios - 在 `touchesBegan:withEvent:` 之后禁用所有 UIPanGestureRecognizers

ios - 存储 iPad/iPhone 应用程序数据的最佳方式

android - 有没有办法使用 just_audio 快进?

arrays - 错误: Cannot convert value of type "[String]" to expected argument type "String?"

ios - NSMutable 字典无法正常工作

java - 如何停止已经播放的声音并立即开始另一个

ios - 如何在再次单击表格 View 时停止歌曲并在单击另一个单元格时播放另一首歌曲

ios - AVAudioPlayer 不播放音频 Swift

ios - 应用程序在后台 iOS 中播放音频