IOS AVAudioPlay 播放本地音频没声音问题

来源:互联网 发布:淘宝产品突然被删除 编辑:程序博客网 时间:2024/04/28 14:58


self.avAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:bellVoicePath] error:&bellVoiceError];    self.avAudioPlayer.numberOfLoops = 3;    self.avAudioPlayer.volume = 1.0;    if (bellVoiceError)    {        NSLog(@"%@",[NSString stringWithFormat:@"bell Play Voice Error :%@",bellVoiceError]);        [StaticMethods writelog:[NSString stringWithFormat:@"bell Play Voice Error :%@",bellVoiceError]];    }    if ([self.avAudioPlayer prepareToPlay])    {        [self.avAudioPlayer play];    }

请注意检查:

1,是否将AudioPlayer声明为全局变量;

2,本地音乐文件是否存在,路径是否正确;

3,初始化NSURL时,是否使用的是  fileURLWithPath . (如果错用 URLWithString 也是会造成初始化失败的

4,还有一种可能就是  设备 设置的是 静音 

0 0
原创粉丝点击