I want to add the following method in for loop.
func playQuequeSounds(time:String){
let song1 = AVPlayerItem(URL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("estimatedTime", ofType: "mp3", inDirectory: "Audiofiles")!))
let song2 = AVPlayerItem(URL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(time, ofType: "mp3", inDirectory: "Audiofiles")!))
let song3 = AVPlayerItem(URL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("minutes", ofType: "mp3", inDirectory: "Audiofiles")!))
self.queueplayer = AVQueuePlayer(items: [song1,song2,song3])
self.queueplayer.actionAtItemEnd = AVPlayerActionAtItemEnd.Advance
self.queueplayer.play()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "playerDidFinishPlaying:", name: AVPlayerItemDidPlayToEndTimeNotification , object: song3)
}
i add the above method in viewWillApear
override func viewWillAppear(animated: Bool) {
voiceRouteTableView.reloadData()
NSNotificationCenter.defaultCenter().removeObserver(self)
for i in 0...voicesRoutes.count{
flag=false
self.playQuequeSounds(String(i+1))
while flag==false{
}
}
sleep(2)
}
The problem is that the loop runs very quicky and doesn't wait the avqueueplayer to finish the play. Add notification and change the code into the loop for waiting until the follow method call but the same problem.
func playerDidFinishPlaying(note: NSNotification) {
flag=true
}