我已将音频工具箱和 avfoundation 导入到我的类(class)中,并将框架添加到我的项目中,并使用此代码播放声音:
- (void)playSound:(NSString *)name withExtension:(NSString *)extension
{
NSURL* soundUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:name ofType:extension]];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
audioPlayer.delegate = self;
audioPlayer.volume = 1.0;
[audioPlayer play];
}
我这样调用它:
[self playSound:@"wrong" withExtension:@"wav"];
但是我得到的声音为零。
最佳答案
更新的答案:
I've got the issue. It's with ARC and has nothing to do with prepareForPlay. Simply make a strong reference to it and it will work.
如下用户所述:Kinderchocolate
:)
在代码中:
.h
~
@property (nonatomic, strong) AVAudioPlayer *player;
.m
~
@implementation
@synthesize _player = player;
关于iphone - AVAudioPlayer 没有声音输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10856332/