【发布时间】:2018-10-30 05:02:04
【问题描述】:
我在项目文件夹中有一个 mp3 文件,它会反复播放,但播放器在播放完 mp3 时会出现延迟。此延迟约为 1 秒。如何减少延迟并不断重播?我使用了循环数,但没有帮助。代码如下:
DispatchQueue.main.async
{
guard let url = Bundle.main.url(forResource: "finalbreathin", withExtension: "mp3") else { return }
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
try AVAudioSession.sharedInstance().setActive(true)
/* The following line is required for the player to work on iOS 11. Change the file type accordingly*/
self.player = try AVAudioPlayer(contentsOf: url)
//iOS 10 and earlier require the following line:
self.player = try AVAudioPlayer(contentsOf: url, fileTypeHint: AVFileType.mp3.rawValue)
guard let player = self.player else { return }
player.numberOfLoops = -1
self.imageanimate.startAnimating()
player.play()
} catch let error {
print(error.localizedDescription)
}
}
【问题讨论】:
-
我已经使用播放器的循环数音频大约是 9 秒长
-
请添加您的代码
标签: iphone swift4 avplayer avaudioplayer audio-player