【发布时间】:2015-07-09 01:16:44
【问题描述】:
我正在尝试为我的自定义键盘播放 Tock 声音。
我尝试过的:
[[UIDevice currentDevice] playInputClick];
和
NSString *path = [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] pathForResource:@"Tock" ofType:@"aiff"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound(soundID);
AudioServicesDisposeSystemSoundID(soundID);
和
AudioServicesPlaySystemSound(0x450);
和
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"test" ofType: @"mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundFilePath ];
myAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
myAudioPlayer.numberOfLoops = 1;
[myAudioPlayer play];
这给了我一个错误:
AudioSessionClient: Couldn't connect to com.apple.audio.AudioSession
Couldn't connect to com.apple.audio.AudioQueueServer; AudioQueue will not be usable
并且还研究了这个link
当我在我的 ViewControllers(不是自定义键盘)中尝试这些代码时,一切都奏效了。但是当我在我的自定义键盘上测试它时,它至少闲置了 10 秒,我什么也听不见。
我还确保我的 iPhone 未处于静音模式,扬声器未损坏,键盘点击已启用。我在 iPhone 和 iPad 上测试了这些代码,结果是一样的
Xcode 版本 6.3.1 iOS 8.3 版
我做错了什么?提前致谢。
【问题讨论】:
标签: ios objective-c iphone xcode keyboard