【发布时间】:2020-04-05 14:31:48
【问题描述】:
我正在使用 AVAudioPlayer,并希望用户可以在循环播放后重新开始播放。对于用户反馈,我使用了 UIAlertController,但我仍然很难使用 AVAudioPlayer 完成重播。我希望用户可以随心所欲地选择重播,直到他选择否。
这是我到目前为止的代码,但是如果用户选择“是”该怎么办...请参阅下面代码中的注释。
// schedule the audio file
[self->_playerNode scheduleFile:self->_file atTime:nil completionHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:@"End of file"
message:@"play again?"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* yes = [UIAlertAction
actionWithTitle:@"YES"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
// WHAT TO DO HERE????
[alert dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* no = [UIAlertAction
actionWithTitle:@"NO"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
NSLog(@"Stop");
[self->_engine stop];
[session setActive:false error:nil];
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:yes];
[alert addAction:no];
[self presentViewController:alert animated:YES completion:nil];
});
}];
// playback the audio file
[self->_playerNode play];
感谢您的帮助!
【问题讨论】:
标签: ios objective-c avaudioplayer uialertcontroller