我需要以编程方式单击一个按钮:[play sendActionsForControlEvents:UIControlEventTouchUpInside];
但是当我这样做时,void 被调用了两次!我需要启动一个 AVPlayer(在 ViewDidLoad 中),但音乐也开始了两次。请帮忙 :)。
播放代码:
- (IBAction)playStream:(id)sender {
NSLog(@"%@", @"PlayStream clicked: ", sender);
if(clicked == 0) {
clicked = 1;
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
[play setImage:[UIImage imageNamed:@"pause"] forState:UIControlStateNormal];
[playerr play];
}
else {
[playerr stop];
[play setImage:[UIImage imageNamed:@"Start"] forState:UIControlStateNormal];
[audio setActive:NO error:nil];
clicked = 0;
}
}