ios - AudioServicesPlaySystemSound sound volume dependency -
i'm making ios keyboard extension.
to play click sound, used audioservicesplaysystemsound
.
however users reported click sound depends on 'bell sound volume(bell icon)' , 'normal sound volume(speaker icon)'
i tested on apple memo app , found there cases inconstant dependency.
here code init
func inittypesound(soundindex: int) { let bundle = nsbundle.mainbundle() var = 0 ; < max_type_sound_count ; i++ { if let url = bundle.urlforresource(nsstring(format: "type%d_%d", soundindex, i) string, withextension: "wav") { // file exist var soundid : systemsoundid = 0 audioservicescreatesystemsoundid(url, &soundid) mtypesoundids.insert(soundid, atindex: i) } else { // no file } } }
and code play
func play(soundtype: kksoundtype) { if (!mhaspermission || !missound) { return } var session = avaudiosession.sharedinstance() let systemvolumn = session.outputvolume if (systemvolumn == 0) { return } var soundid : systemsoundid! switch (soundtype) { case .type: let rand = int(arc4random_uniform(uint32(mtypesoundids.count))); soundid = mtypesoundids[rand]; break case .space: soundid = mspacesoundid; break default: return } if missound { audioservicesplaysystemsound(soundid) } }
Comments
Post a Comment