オーディオ ファイルの再生が終了したときに何かしようとしているだけですが、うまくいきません。
私の .h ファイルには、次のものがあります。
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
@interface soundViewController : UIViewController
<AVAudioPlayerDelegate>
{
//various outlets
}
@property (strong, nonatomic) AVAudioPlayer *audioPlayer;
@end
そして、私が持っている.mファイルで:
#import "soundViewController.h"
@interface soundViewController ()
@end
@implementation soundViewController
@synthesize audioPlayer;
メソッドは次のとおりです。
- (void) playWord{
Word *currentWord = [[Word alloc]init];
currentWord = [testWords objectAtIndex:wordNum-1];
NSString *item = [currentWord word];
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@.mp3", [[NSBundle mainBundle] resourcePath], item]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = 0;
if (audioPlayer == nil){
NSLog(@"error in audioPlayer");
}
else{
[audioPlayer play];
NSLog(@"Playing word");
}
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
if (flag==YES){
NSLog(@"Finished!");
}
}
それで...すべて問題なく動作しますが(大文字で始まるとサウンドファイルが機能しないという事実を除けば)、サウンドが終了したときに「Finished」というログメッセージが表示されないのはなぜですか?
助けてくれてありがとう、モートン