菜鸟教程小白 发表于 2022-12-13 12:50:20

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


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

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

<p>在我的 (void) 我有 <code>//and </code></p>

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

<p>谢谢:) </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>停止 <strong>AVAudioPlayer</strong> 不会重置播放头。</p>

<blockquote>
<p>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.</p>
</blockquote>

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

<p>例子-</p>

<pre><code>playSound2.currentTime = 0.0;
;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - AVFoundation AVAudioPlayer 停止正在暂停 - Objective-C,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/34322270/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/34322270/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - AVFoundation AVAudioPlayer 停止正在暂停 - Objective-C