IPhone SDK: play a single WAV with a button

I am currently testing 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];

However, the SDK says that the ViewController does not implement the AVAudioPlayer delegate.

Does any body have ideas on how to play WAV (or M4a) using the 2.2 SDK?

+3
source share
4 answers

You need to add the <AVAudioPlayerDelegate>controller class declarations at the end of the following lines:

@interface MyViewController: UIViewController <AVAudioPlayerDelegate>

This will probably create a few more warnings about delegation methods that you need to implement - follow them and you will be well off.

+9
source

. NSURL -URLWithString: - , . , , . , ?

+1

, . , concurrency, .

+1

iPhoneToot.com itootSound VIDEO, , wav 2 . iPhoneToot.com. , !

-1

All Articles