ios - AVAudioPlayer play multiple times same sound without interrupting -


i have scrollview. , want play sound everytime reach 1/7 of it. when user scrolls works because sound finished before other 1 gets fired.

but if fast : have 2 options :

  • ignore following sound should fire
  • stop previous 1 , play following

but want have first 1 finishing playing if second (or 3rd, 4th etc.) has started playing.

can 1 avaudioplayer ?

var alertsound = nsbundle.mainbundle().urlforresource("transit", withextension: "aif") avaudiosession.sharedinstance().setcategory(avaudiosessioncategoryambient, error: nil) avaudiosession.sharedinstance().setactive(true, error: nil)  var error:nserror? audioplayer = avaudioplayer(contentsofurl: alertsound, error: &error) audioplayer.preparetoplay() 

to achieve want you'll need multiple avaudioplayers, 1 player won't job. audiotoolbox framework cater requirements.

you create system sound id sound , fire off whenever want. once it's fired sound play out, down side no control on volume shouldn't matter in case.

basic example (obj-c sorry)

    nsstring *path=[[nsbundle mainbundle] pathforresource: @"soundname" oftype:@"aif"];      systemsoundid soundid;     audioservicescreatesystemsoundid((__bridge cfurlref)([nsurl fileurlwithpath:path]), &soundid);     audioservicesplaysystemsound(soundid); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -