我试图让这首歌在歌曲结束时重播,但它似乎不起作用。这就是我实现它的方式:
var music1 : AVAudioPlayer! = AVAudioPlayer()
func setUpMusic(){
let music1Path = NSBundle.mainBundle().pathForResource("Lost", ofType:"mp3")
let fileURL1 = NSURL(fileURLWithPath: music1Path!)
do{
music1 = try AVAudioPlayer(contentsOfURL: fileURL1, fileTypeHint: nil)
}
catch{}
music1.play()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(GameScene.replayFirstSong(_:)), name: AVPlayerItemDidPlayToEndTimeNotification, object: music1)
}
func replayFirstSong(note: NSNotification){
print("Inside Replay first song")
music1.currentTime = 0
music1.play()
}
知道如何让这首歌不断循环播放
最佳答案
尝试使用numberOfLoops
:
swift :
var numberOfLoops: Int
目标-C
@property NSInteger numberOfLoops
设置为-1会无限循环...
关于 swift : Replay AVAudioPlayer when song ends,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36491027/