在不同的iOS设备上同步声音的问题
|
我创建了一个音乐应用程序,当对象与网格边缘碰撞时可以播放9种声音之一。这在模拟器上可以完美地运行,但是在第四代设备上不能完全同步,并且在iPhone 3g上完全不同步。
所谓不同步,是指混响每隔0.2秒发生一次,以匹配网格移动的速度,并且由于混响不是同时在设备上发出,因此声音听起来不正确。另外,通过查看iPhone 3g,您可以看出网格绝对不是每0.2秒重绘一次-速度要慢得多。
这是基本代码:
- (void)startTime {
[musicTimer setFireDate:[NSDate distantFuture]];
musicTimer = [NSTimer scheduledTimerWithTimeInterval: 0.01
target: self
selector: @selector(checkTime)
userInfo: nil
repeats: YES];
}
- (void)checkTime {
float timeSince = [[NSDate date] timeIntervalSinceDate:lastPlayed];
if(timeSince >= 0.2){
[self repositionBlocks];
}
}
- (void)repositionBlocks {
//Check which sounds need to play and call the play function on each of them
//The following line would play the sound if a collision occurred
Sound *sound = [[Sound alloc] init];
[sound play:@\"01.wav\"];
[sound release];
[self redrawGrid]; //Redraws the grid with the new positions
[lastPlayed release];
lastPlayed = [[NSDate date] retain];
}
这是我的Sound类中的播放功能
- (void)play:(NSString *)soundFile {
NSString *path;
NSString *fileName = [NSString stringWithFormat:@\"/%@\", soundFile];
path = [NSString stringWithFormat:@\"%@%@\", [[NSBundle mainBundle] resourcePath], fileName];
SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
[filePath release];
}
如果有人能在这个问题上提供任何帮助,我将非常感谢
谢谢
编辑:我做了一些测试,并将其缩小为NSTimer的问题,在模拟器上,它每0.2秒触发一次,但在设备上,它每0.4秒至0.6秒触发一次。我已经在互联网上进行搜索,关于NSTimers的准确性以及是否应该用于此方面,有很多信息,但是我找不到任何替代方法。
没有找到相关结果
已邀请:
1 个回复
僻朵庙惩竣