iphone - 无法启动音频播放器

标签 iphone ios audio avaudioplayer

我有一个音频播放器,但无法播放声音,有人知道为什么吗?
而且我已经导入了AVFoundationFramework.h

这是代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


    NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"begin" ofType:@"mp3"]];
    AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
    [audioPlayer play];
    audioPlayer.numberOfLoops=-1;
}

最佳答案

添加代表:

 [audioPlayer setDelegate:self];

并确保正确设置音量。

关于iphone - 无法启动音频播放器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14361603/

相关文章:

iphone - 如何以编程方式获取iphone的IP地址

iphone - NSTimer 的问题

ios - 快速调整图像大小

android - 从 Intent 中获取音频uri

java - Xuggler的IPacket如何与FLV标签或标签部分对应?

ios - 如何以编程方式使用自动布局排列这三个 UILabel?

ios - UITableViewCell 中的 UIScrollView 在表格滚动时不断重新加载

ios - 阻止 UIWebView 上的交互,同时保持其滚动功能

ios - 如何确定 UITextField 内文本的大小(包括光标)?

audio - 在 nim 中使用 sdl2/mixer 播放音频的时间不可靠