【发布时间】:2014-03-21 21:17:42
【问题描述】:
我很难按照 Apple 的文档来使用 AVAudioPlayer 类播放一个小的 .wav 文件。我也不确定基本音频播放需要哪些工具箱。到目前为止,我已经导入:
AVFoundation.framework
CoreAudio.framework
AudioToolbox.framework
这是我的代码.h 和.m:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController : UIViewController <AVAudioPlayerDelegate>
- (IBAction)playAudio:(id)sender;
@end
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)playAudio:(id)sender {
NSLog(@"Button was Pressed");
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"XF_Loop_028" ofType:@"wav"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
// create new audio player
AVAudioPlayer *myPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:fileURL error:nil];
[myPlayer play];
}
@end
我似乎没有任何错误。但是,我没有收到任何音频。
【问题讨论】:
标签: ios core-audio