我想播放的声音不是从mp3文件的开头,而是从开始后的14s播放。我有以下声音播放代码,但我没有成功找到解决方案:
if let textAudio = textAudio {
let wait = SKAction.wait(forDuration: 0.1)
let play = SKAction.play()
if view.scene! == scene02 {
// play 14s after begining
}
textAudio.run(SKAction.sequence([wait, play]))
}
答案 0 :(得分:3)
您可以按照here的说明使用AVAudioPlayer
和currentTime
方法:
import AVFoundation
var textAudio: AVAudioPlayer?
let path = Bundle.main.path(forResource: "example.mp3", ofType:nil)!
let url = URL(fileURLWithPath: path)
do {
textAudio = try AVAudioPlayer(contentsOf: url)
textAudio?.currentTime = TimeInterval(14.0)
textAudio?.play()
} catch {
// couldn't load file :(
}