ios - AVFoundation AVAudioPlayer 停止暂停 - Objective-C

标签 ios objective-c avaudioplayer

很难显示代码,因为它在代码中不明显。我有一些操作,例如 -(IBAction)PlaySound1:(id)sender;-(IBAction)PlaySound2:(id)sender; 和音频文件。我的声音工作正常。我还有 -(void)Stop;。当按下播放声音 1 时,它会调用停止方法并停止声音 2。与声音 2 相同。

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

在我的 (void) 中,我有 [PlaySound1 stop]//和 [PlaySound2 stop]

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

谢谢 :)

最佳答案

停止 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.

要从头开始继续播放,请在调用播放之前将 currentTime 属性设置为 0.0。

例子-

playSound2.currentTime = 0.0;
[playSound2 play];

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

相关文章:

c# - 从 ScrollView ( subview )内部将 View 推送到导航 Controller

iOS - 创建新目标后生成的 IPA 大小增长很多

ios - 第二个 UIWindow 中的方向更改

cocoa - 如何观察像 "object.attribute"这样的关键路径

ios - 从主线程访问布局引擎后,不得从后台线程执行对布局引擎的修改

ios - 试图在 iOS 中制作免责声明 View Controller

ios - 在 Swift 的绘图类中设置自定义 RGB 颜色

ios - 以编程方式将视网膜照片分配给 UIButton

ios - 音频录制和播放同时进行

ios - 如何在后台运行 iOS 应用程序来解析海量数据 API?