0

I want to play sound in randomly without repeating at once time.All sound played after again start new cycle of random sound.

For Example:we have 5 file.

start random playing:3,1,5,2,4(this is right)--- 3,1,3,5,2,4(this is wrong)

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
vivek
  • 21
  • 2
  • Are you struggling with how to code it or the concept? If it is the concept I can post some pseudocode to show you how the logic would work if you are stuck with a specific code problem please post your current code. – IfTrue Aug 11 '15 at 14:00
  • One way you could play your sounds in a (pseudo) random, non-repeating order is to store the file names in an array, shuffle it using [one of the methods provided here](http://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array), then iterate through the array and play each of the sounds. – Serlite Aug 11 '15 at 14:15

1 Answers1

0

Conceptually this is how I would approach this problem

  • Store all your sounds into an array
  • randomize your array
  • Store that array into a nsuserdefaults. So that in case user closes and relaunches app then you still have that randomized array
  • count how many sounds have been played. Store the count into a nsuserdefaults as well. (for same reason as above)
  • Now once the count reaches array count then randomize the array again and start all over.

Kinda makes sense?

Sam B
  • 27,273
  • 15
  • 84
  • 121