2

There is an option numberofloops in AVAudioPlayer which repeats a sound file for a specified number of times.

I have to implement this type of function in AVAudioPlayerNode and I found an option just to loop a sound file in an infinite number of times in a loop using the following code

audioPlayerNode.scheduleBuffer(audioFileBuffer, atTime: nil, options:.Loops, completionHandler: nil)

Is it possible to repeatedly play a file in a fixed number of times like as AVAudioPlayer? Is there any code sample to achieve this?

Kuldeep
  • 4,466
  • 8
  • 32
  • 59
Simant
  • 3,142
  • 4
  • 32
  • 61

1 Answers1

1

Am not sure if there is an option to do it however you can achieve this by creating a simple function like below.

func playBuffer(buffer,times) {
for (var i=1;i<=times;i++) {   
audioPlayerNode.scheduleBuffer(audioFileBuffer)
}
}

and then you call the function like this

playBuffer(buffer,3) // to execute three times.
// or
playBuffer(buffer,1) // to execute one time.

p.s: This is almost like a pseudo code just to show the logic. you have to write it in swift.

Satizh J
  • 307
  • 4
  • 14