我想知道如何让我的应用知道音频何时停止。我按下播放按钮时会录制30分钟的音频。然后将播放按钮更改为暂停按钮。我希望暂停按钮在音频完成时切换回播放按钮。我正在使用AVAudioPlayer。我该怎么做呢?谢谢!
答案 0 :(得分:1)
AVAudioPlayerDelegate包含一个名为audioPlayerDidFinishPlaying:successfully:
的方法。您可以覆盖该方法并将播放/暂停按钮登录到那里。
这样的事情:
在.h
#import <UIKit/UIKit.h>
#import "AVFoundation/AVAudioPlayer.h"
@interface ViewController : UIViewController<AVAudioPlayerDelegate>
@end
在.m
@implementation ViewController{
AVAudioPlayer *_player;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_player.delegate = self;
}
-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
//show play button
}
@end
有关AVAudioPlayerDelegate here
的更多信息