相关疑难解决方法(0)

声音没有播放AVAudioPlayer

我搜索过,我相信我的问题非常独特.我知道使用AVAudioPlayer时的模拟器5.1错误,这不是我的问题.我在iOS 5.1设备上运行.

这是我的头文件:

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVAudioPlayer.h>

-(IBAction)pushBell;

@end
Run Code Online (Sandbox Code Playgroud)

和我的实施文件:

#import "BellViewController.h"

@interface BellViewController ()

@end

@implementation BellViewController

-(IBAction)pushBell {

    NSString *soundPath =[[NSBundle mainBundle] pathForResource:@"bell1" ofType:@"caf"];
    NSURL *soundURL = [NSURL fileURLWithPath:soundPath];
    NSError *error;

    AVAudioPlayer *theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&error];
    [theAudio setDelegate:self];
    [theAudio setNumberOfLoops:0];
    [theAudio play];

}

@end
Run Code Online (Sandbox Code Playgroud)

我的.xib中有一个按钮来播放该文件.

为了确保我正确引用了我的音频文件,我故意输入了错误的文件名,实际上我得到了一个例外.为了确保文件可播放,我将其邮寄给自己并在设备上播放.

当我点击按钮时,我什么都没听到.没有错误.我不知道出了什么问题.

更多信息 iPhone 4与iOS 5.1 Xcode 4.3.2音频大约700kbps转换为.caf格式使用afconvert从一个大的.wav文件.

iphone audio core-audio avaudioplayer ios

8
推荐指数
3
解决办法
2万
查看次数

标签 统计

audio ×1

avaudioplayer ×1

core-audio ×1

ios ×1

iphone ×1