声音播放完毕后,我正在执行一些代码,但不知道最好的方法是什么。我已经看过performSelectorOnMainThread....
,但没有完全理解它 - 即使如此,我不确定这是否是解决问题的最佳方法。我想在声音播放完毕后更改标签的文字颜色。我会很感激一些帮助。我的代码如下:声音播放完毕后执行代码的最佳方式
-(void) playWordSound:(UILabel *)label
{
NSString *path;
SystemSoundID soundId;
switch (label.tag)
{
case 1:
path = [[NSBundle mainBundle] pathForResource:@"humpty" ofType:@"wav"];
break;
case 2:
path = [[NSBundle mainBundle] pathForResource:@"dumpty" ofType:@"wav"];
break;
case 3:
path = [[NSBundle mainBundle] pathForResource:@"saty" ofType:@"wav"];
break;
case 4:
path = [[NSBundle mainBundle] pathForResource:@"on 2" ofType:@"wav"];
break;
case 5:
path = [[NSBundle mainBundle] pathForResource:@"a 3" ofType:@"wav"];
break;
case 6:
path = [[NSBundle mainBundle] pathForResource:@"wall" ofType:@"wav"];
break;
}
NSURL *url = [NSURL fileURLWithPath:path];
AudioServicesCreateSystemSoundID((CFURLRef)objc_unretainedPointer(url), &soundId);
AudioServicesPlaySystemSound(soundId);
//this is where i want to change the color of the label
}
谢谢您的回答。我在'.h文件中有'#import #import '但是出现了一些错误 - itemStatusContext和player都抛出了未声明的标识符错误 –
garethdn
您只需要AVFoundation,但是你必须声明所有的变量,上面的代码只是一个片段,你仍然需要声明一个“AVQueuePlayer * player”和一个“静态常量NSString * ItemStatusContext”。查看Xcode文档中的播放系统指南。 – codeghost