AVAudioPlayer 不从文件开始播放

AVAudioPlayer not playing from start of file

我有一个使用 AVFoundation 的应用程序,它使用 mp3 声音文件作为音效播放。它的记录长度为 90 秒。然而,我反复播放它,根据不同的事情断断续续,使用 tickingSounds.play() 和 tickingSounds.stop() 播放不同的时间长度。然而,一旦我达到 90 秒,它似乎就不会再播放了。我假设 play() 命令从我上次停止的地方恢复?

我的问题是如何重置它的播放位置,或者我是否遗漏了其他内容?

你应该设置:

numberOfLoops

将 属性 numberOfLoops 设置为 -1,它将进入无限循环。

numberOfLoops

The number of times a sound will return to the beginning, upon reaching the end, to repeat playback.

@property NSInteger numberOfLoops Discussion A value of 0, which is the default, means to play the sound once. Set a positive integer value to specify the number of times to return to the start and play again. For example, specifying a value of 1 results in a total of two plays of the sound. Set any negative integer value to loop the sound indefinitely until you call the stop method.

Availability Available in iOS 2.2 and later. Declared In AVAudioPlayer.h