gpt4 book ai didi

swift : Replay AVAudioPlayer when song ends

转载 作者:搜寻专家 更新时间:2023-10-31 23:00:27 46 4
gpt4 key购买 nike

我试图让这首歌在歌曲结束时重播,但它似乎不起作用。这就是我实现它的方式:

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会无限循环...

https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/#//apple_ref/occ/instp/AVAudioPlayer/numberOfLoops

关于 swift : Replay AVAudioPlayer when song ends,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36491027/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com