代表AVAudioPlayer
可以設置爲班級成員audioPlayerDidFinishPlaying
?如何將代表設置爲班級方法
我想使用類方法播放聲音文件,但無法弄清楚如何將setDelegate:
設置爲audioPlayerDidFinishPlaying
類方法。
我有一個叫做'common'的小類,只有靜態成員。
請參見下面的 '< < < <' 標誌......
@class common;
@interface common : NSObject <AVAudioPlayerDelegate> {
}
+(void) play_AV_sound_file: (NSString *) sound_file_m4a;
+(void) audioPlayerDidFinishPlaying: (AVAudioPlayer *) player successfully: (BOOL) flag
@end
@implementation共同
AVAudioPlayer * audioPlayer;
// Starts playing sound_file_m4a in the background.
+(void) play_AV_sound_file: (NSString *) sound_file_m4a
{
printf("\n play_AV_sound_file '%s' ", [sound_file_m4a UTF8String]);
NSString *soundPath = [[NSBundle mainBundle] pathForResource:sound_file_m4a ofType:@"m4a"];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: soundPath] error:&error ];
[audioPlayer setDelegate:audioPlayerDidFinishPlaying]; //<<<<<<<<<< causes error
>>> what should setDelegate: be set to? <<<
[audioPlayer prepareToPlay];
[audioPlayer play];
}
+(void) audioPlayerDidFinishPlaying: (AVAudioPlayer *) player successfully: (BOOL) flag
{
printf("\n audioPlayerDidFinishPlaying");
[audioPlayer release];
audioPlayer=nil;
[audioPlayer setDelegate:nil];
}
@end