在 Cocoa Touch 中循环播放声音
我有一个矩形按钮,当用户按一次时。声音响起 但我希望这样,当用户双击按钮时,声音会不断循环,直到用户决定按下以停止声音。 这是播放声音的代码。
- (IBAction)oneSound:(id)sender; {
NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"wav"];
if (theAudio) [theAudio release];
NSError *error = nil;
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
if (error)
NSLog(@"%@",[error localizedDescription]);
theAudio.delegate = self;
[theAudio play];
}
谢谢!
I have a rectangle button, when the user presses it once. the sound plays
But I want it so when the user double taps the button, the sound continously loops till the user decided to press to stop the sound.
This is the code to play the sound.
- (IBAction)oneSound:(id)sender; {
NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"wav"];
if (theAudio) [theAudio release];
NSError *error = nil;
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
if (error)
NSLog(@"%@",[error localizedDescription]);
theAudio.delegate = self;
[theAudio play];
}
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加这一行:
负值使播放器永远循环直到停止。
Add this line:
The negative value makes the player loop forever until it is stopped.