可以将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
@实现常见
AVAudioPlayer* 音频播放器;
// 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