当位置速度降低时播放音频播放器

时间:2013-05-20 04:21:51

标签: ios objective-c ios5 cllocation

当位置速度大于20时,如何播放audioplayer,计时时间开始为5秒,突然定位时 速度(速度从20 t0 0降低)等于零它播放音频播放器。我试试这个,但没有任何事情发生,请帮助我。这是我的代码

int i;

- (void)locationUpdate:(CLLocation *)location{
    speedLabel.text = [NSString stringWithFormat:@"%.2fmph",[location speed]*2.236936284];

    if (location.speed >= 10)
    {
        [self performSelector:@selector(doThis) withObject:nil afterDelay:5];
        if (location.speed ==0) {
            [audioPlayer play];
        }
    }
}

-(void)doThis{
    if(i %5 == 0)     
    {
        [CLController.locMgr startUpdatingLocation];
    }
}

1 个答案:

答案 0 :(得分:0)

您的状况检查不会播放音频。按照给出的更改进行更改

int i;

- (void)locationUpdate:(CLLocation *)location{
    speedLabel.text = [NSString stringWithFormat:@"%.2fmph",[location speed]*2.236936284];

    if (location.speed >= 10)
    {
        [self performSelector:@selector(doThis) withObject:nil afterDelay:5];

    }
    else if (location.speed ==0) {
        [audioPlayer play];
    }

}

-(void)doThis{
if(i %5 == 0)     
{
    [CLController.locMgr startUpdatingLocation];
}
}