简体   繁体   中英

how to play random sound without repeat ?after playing all file then again start new cycle of sound

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)

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM