在我的应用中,声音播放为无限循环。但是当第一个循环结束时,它会等待2到3秒再次开始。我想禁用循环之间的间隔。你能帮帮我吗?
import UIKit
import AVFoundation
class ViewController: UIViewController {
var AudioPlayer = AVAudioPlayer();
@IBOutlet weak var playb: UIButton!
@IBAction func play(sender: UIButton) {
if !AudioPlayer.playing {
AudioPlayer.numberOfLoops = -1
AudioPlayer.play()
playb.setTitle("Stop Rain", forState: UIControlState.Normal)
} else {
AudioPlayer.stop()
playb.setTitle("Start Rain", forState: UIControlState.Normal)
}
}
override func viewDidLoad() {
super.viewDidLoad()
var rainSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("srs", ofType: "wav")!)
AudioPlayer = AVAudioPlayer(contentsOfURL: rainSound, error: nil)
AudioPlayer.prepareToPlay()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
答案 0 :(得分:0)
你在播放什么文件格式?
尝试播放非分组化文件格式,例如.wav或.aiff。像MP3和AAC这样的格式有少量的前导和尾随沉默,我认为AVAudioPlayer
不允许你修剪!