iPhone SDK:通过按钮播放单个WAV [英] iPhone SDK: Play a single WAV from a button
本文介绍了iPhone SDK:通过按钮播放单个WAV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在尝试此代码:
I am currently trying out this code:
NSString *path = [[NSBundle mainBundle] pathForResource:@"dream" ofType:@"m4a"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
但是,SDK表示ViewController没有实现AVAudioPlayer委托.
However, the SDK says that the ViewController does not implement the AVAudioPlayer Delegate.
关于使用2.2 SDK播放WAV(或M4a)的任何想法吗?
Any body any ideas on how to play a WAV (or M4a) using the 2.2 SDK?
推荐答案
您需要将<AVAudioPlayerDelegate>
添加到控制器的类声明的末尾,如下所示:
You need to add <AVAudioPlayerDelegate>
to the end of your controller's class declaration, along these lines:
@interface MyViewController : UIViewController <AVAudioPlayerDelegate>
这可能会生成一些有关您需要实现的委托方法的警告-遵循这些警告,您就可以办事了.
This'll probably generate some more warnings about delegate methods you need to implement - follow those and you'll be good to go.
这篇关于iPhone SDK:通过按钮播放单个WAV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文