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 common
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