本文介绍了AVAudioPlayer,无声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经导入的音频工具箱avfoundation上我的课,并添加了框架,以我的项目,我用这个code播放声音:

I have imported audio toolbox and avfoundation to my class and added the frameworks to my project and am using this code to play a sound:

- (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];
}

我把它称为是这样的:

I call it like this:

[self playSound:@"wrong" withExtension:@"wav"];

零声。任何帮助深表AP preciated,谢谢。

Zero sound. Any help is much appreciated, thanks.

推荐答案

更新的答案:

我有这个问题。这是一个与ARC和有无关
  prepareForPlay。简单地作出强烈参考它和它的工作。

由用户如下所述:健达巧克力:)

在code:

.h
~
@property (nonatomic, strong) AVAudioPlayer *player;


.m
~
@implementation
@synthesize _player = player;

这篇关于AVAudioPlayer,无声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 01:01