OGeek|极客世界-中国程序员成长平台

标题: ios - AVFoundation AVAudioPlayer 停止正在暂停 - Objective-C [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 12:50
标题: ios - AVFoundation AVAudioPlayer 停止正在暂停 - Objective-C

显示此代码相当困难,因为它在代码中并不明显。我有一些 Action ,例如 -(IBAction)PlaySound1id)sender;-(IBAction)PlaySound2id)sender; 和音频文件。我的声音一切正常。我也有 -(void)Stop;。当按下播放声音 1 时,它会调用方法 Stop 并停止声音 2。与声音 2 相同。

我遇到的问题是,当您播放声音 1 并停止声音 2 时,当您播放声音 2 时,它会从停止的地方开始。

在我的 (void) 我有 [PlaySound1 stop]//and [PlaySound2 stop]

如果有人可以提供帮助,那就太好了。如果有不清楚的地方,请对此发表评论,我会尝试更好地解释它。

谢谢



Best Answer-推荐答案


停止 AVAudioPlayer 不会重置播放头。

The stop method does not reset the value of the currentTime property to 0. In other words, if you call stop during playback and then call play, playback resumes at the point where it left off.

要从头恢复播放,请在调用 play 之前将 currentTime 属性设置为 0.0。

例子-

playSound2.currentTime = 0.0;
[playSound2 play];

关于ios - AVFoundation AVAudioPlayer 停止正在暂停 - Objective-C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34322270/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4