iOS 带有声音剪辑的字母表应用程序
iOS app for alphabets with sound clips
我正在开发一个包含 A 到 Z 字母表的 iOS 应用程序。我有每个字母的声音片段。我有一个按钮 "next",它会在单击时更改字母表。现在,我希望在单击下一步按钮时播放特定字母表的特定声音片段。
- (void)viewDidLoad {
[super viewDidLoad];
NSURL * soundURL = [[NSBundle mainBundle] URLForResource:@"apple" withExtension:@"mp3"];
AudioServicesCreateSystemSoundID((CFURLRef)CFBridgingRetain(soundURL), &fruitsound);
}
- (IBAction)btnPlayClicked:(id)sender {
AudioServicesPlaySystemSound(fruitsound);
}
你需要有办法将他们敲击的字母转换成你想要播放的声音。最简单的方法是将声音文件命名为与字母完全相同;)还有其他更复杂(但在其他方面更好)来解决这个问题,但为了让你开始尝试这样的事情:
- (IBAction)btnPlayClicked:(UIbutton)sender {
// Get the letter from the button that was tapped and use that as the sound file name
NSString *letter = sender.text.lowercaseString;
NSURL *soundURL = [[NSBundle mainBundle] URLForResource:letter withExtension:@"mp3"];
// Create the sound with that name and play it
AudioServicesCreateSystemSoundID((CFURLRef)CFBridgingRetain(soundURL), &fruitsound);
AudioServicesPlaySystemSound(fruitsound);
}
假设您已将声音命名为 a.mp3、b.mp3 等,这应该可行。
但是,我不知道 fruitsound
定义了什么/在哪里,所以你可能在某处发生了内存泄漏?如果你这样做,你知道在哪个网站上询问它;)
我正在开发一个包含 A 到 Z 字母表的 iOS 应用程序。我有每个字母的声音片段。我有一个按钮 "next",它会在单击时更改字母表。现在,我希望在单击下一步按钮时播放特定字母表的特定声音片段。
- (void)viewDidLoad {
[super viewDidLoad];
NSURL * soundURL = [[NSBundle mainBundle] URLForResource:@"apple" withExtension:@"mp3"];
AudioServicesCreateSystemSoundID((CFURLRef)CFBridgingRetain(soundURL), &fruitsound);
}
- (IBAction)btnPlayClicked:(id)sender {
AudioServicesPlaySystemSound(fruitsound);
}
你需要有办法将他们敲击的字母转换成你想要播放的声音。最简单的方法是将声音文件命名为与字母完全相同;)还有其他更复杂(但在其他方面更好)来解决这个问题,但为了让你开始尝试这样的事情:
- (IBAction)btnPlayClicked:(UIbutton)sender {
// Get the letter from the button that was tapped and use that as the sound file name
NSString *letter = sender.text.lowercaseString;
NSURL *soundURL = [[NSBundle mainBundle] URLForResource:letter withExtension:@"mp3"];
// Create the sound with that name and play it
AudioServicesCreateSystemSoundID((CFURLRef)CFBridgingRetain(soundURL), &fruitsound);
AudioServicesPlaySystemSound(fruitsound);
}
假设您已将声音命名为 a.mp3、b.mp3 等,这应该可行。
但是,我不知道 fruitsound
定义了什么/在哪里,所以你可能在某处发生了内存泄漏?如果你这样做,你知道在哪个网站上询问它;)