Playing system sound without importing your own

后端 未结 10 2149
情深已故
情深已故 2020-11-27 02:26

Is it possible to play already existing system sounds without importing your own?

10条回答
  •  -上瘾入骨i
    2020-11-27 03:11

    For Swift

    import AVFoundation
    
    func play(sound: String) {
            var soundID: SystemSoundID = SystemSoundID()
            let mainBundle = CFBundleGetMainBundle()
            if let ref = CFBundleCopyResourceURL(mainBundle, sound as CFString, nil, nil) {
                AudioServicesCreateSystemSoundID(ref, &soundID);
                AudioServicesPlaySystemSound(soundID);
            }
    }
    

    the implementation of @Krishnabhadra

提交回复
热议问题