如何播放系统快门音?
How can I play the system shutter sound?
在Swift中我会调用这个方法:
AudioServicesPlaySystemSound(1108)
据说我可以使用 SystemSound class 播放系统声音,但我没有看到指定 ID 的方法。我如何在 Xamarin 中执行此操作?
我相信你必须自己导入声音,如SysSound class uses a local sound in the project rather than the sounds that come with iOS. You can follow this guide here。
我在 App Store 指南中找不到任何关于间接使用 Apple 的声音(通过将它们导入您的项目)的内容,但我猜这是不允许的,并且会导致拒绝。因此,您最好在其他地方找到类似的相机快门声音,然后将其与 SysSound class
一起使用
您有几个选择:
使用P/Invoke手动调用方法,像这样:
[DllImport (Constants.AudioToolboxLibrary)]
static extern void AudioServicesPlaySystemSound(uint inSystemSoundID);
并传递ID;也就是说,Apple 没有记录这些数字,因此声音可能会因版本而异,具体取决于它们的注册顺序。您可能想改用:
var sound = SystemSound.FromFile ("/System/Library/Audio/UISounds/photoShutter.caf");
sound.PlaySystemSound ()
在Swift中我会调用这个方法:
AudioServicesPlaySystemSound(1108)
据说我可以使用 SystemSound class 播放系统声音,但我没有看到指定 ID 的方法。我如何在 Xamarin 中执行此操作?
我相信你必须自己导入声音,如SysSound class uses a local sound in the project rather than the sounds that come with iOS. You can follow this guide here。
我在 App Store 指南中找不到任何关于间接使用 Apple 的声音(通过将它们导入您的项目)的内容,但我猜这是不允许的,并且会导致拒绝。因此,您最好在其他地方找到类似的相机快门声音,然后将其与 SysSound class
一起使用您有几个选择:
使用P/Invoke手动调用方法,像这样:
[DllImport (Constants.AudioToolboxLibrary)]
static extern void AudioServicesPlaySystemSound(uint inSystemSoundID);
并传递ID;也就是说,Apple 没有记录这些数字,因此声音可能会因版本而异,具体取决于它们的注册顺序。您可能想改用:
var sound = SystemSound.FromFile ("/System/Library/Audio/UISounds/photoShutter.caf");
sound.PlaySystemSound ()