AVAudioPlayer rate

后端 未结 4 2127
孤独总比滥情好
孤独总比滥情好 2021-01-05 17:41

So I\'m trying to play a sound file at a different rate in iOS 5.1.1, and am having absolutely no luck. So far I have tried setting the rate of the AVAudioPlayer:

         


        
4条回答
  •  清歌不尽
    2021-01-05 18:01

    here is some code that i know works, just re-tested in an app i've been working on. as you mention, using setEnableRate: and setRate: will only work with iOS 5.0 and above. so i use respondsToSelector: to test on the device whether or not the device will accept the request:

    _noticeAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Rooster-mono" ofType:@"wav"]]
                                                          error:nil];;
    if ([_noticeAudio respondsToSelector:@selector(setEnableRate:)])
        _noticeAudio.enableRate = YES;
    if ([_noticeAudio respondsToSelector:@selector(setRate:)])
        _noticeAudio.rate = 2.0;
    

    running on an iOS 5 device, it performs the double-rate successfully. running on iOS 4.3, it plays it at normal speed.

    so, the only way you'll get the proper rate is if your device has iOS 5 on it.

提交回复
热议问题