1

オーディオ ファイルの再生が終了したときに何かしようとしているだけですが、うまくいきません。

私の .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」というログメッセージが表示されないのはなぜですか?

助けてくれてありがとう、モートン

4

1 に答える 1

2

インスタンス化した後、実際にはプレーヤーのデリゲートを次のように設定する必要があります。

audioPlayer.delegate = self;

お役に立てれば!

于 2012-08-31T03:28:05.423 に答える