AVAudioPlayer 的 playAtTime 属性在 IOS 3.0 中不起作用 / App Crash



我开发了一个通用的应用程序,可以从本地读取音频文件,并使用AvAudioPlayer播放。这里我使用AvAudioPlayer的PlayAtTime属性来前进和后退音频。

这里我的问题是这个playAtTime属性在ios 4.0和更高版本中工作良好,而在ios 3.0中不工作。

我提到的框架说- (BOOL)playAtTime:(NSTimeInterval)time NS_AVAILABLE(10_7, 4_0);在某种意义上我不能在ios 3.0中使用它对吗??那么ios 3.0的修复是什么呢

是否有解决这个问题的方法?有什么建议吗??

快速浏览文档会清楚地让你知道它只在iOS 4.0以后可用

适用于iOS 4.0及以上版本。

currentTime

播放点,以秒为单位,在声音的时间轴内与音频播放器相关联。

@property NSTimeInterval currentTime

如果声音正在播放,currentTime是当前的偏移量播放位置,从声音开始以秒为单位测量。如果声音没有播放,currentTime是播放位置的偏移量从调用play方法开始,以秒计声音开始

通过设置此属性,您可以查找声音中的特定点

playAtTime从iOS 4.0开始可用,更多信息请参阅文档;)

http://developer.apple.com/library/ios/文档/AVFoundation/引用/AVAudioPlayerClassReference/引用/Reference.html

如果你不太在意超级精确的同步,你可以试试这样的方法(在IOS4+中也能工作,只是不那么精确)。注意-要取消它,你需要保存返回值并发送一个"[mySavedTimer invalidate]"消息。

@interface AVAudioPlayer (playAtTimePreIOS4)
-(NSTimeInterval) deviceCurrentTime_preIOS4;
-(NSTimer *) playAtTime_preIOS4 :(NSTimeInterval)atTime;
@end

@implementation AVAudioPlayer (playAtTimePreIOS4)
-(NSTimeInterval) deviceCurrentTime_preIOS4 {
    static NSDate *fakeIt = nil;
    if (fakeIt==nil) {
        fakeIt = [[NSDate alloc] init];
    }
    return 0.0-[fakeIt timeIntervalSinceNow];
}
-(NSTimer *) playAtTime_preIOS4 :(NSTimeInterval)atTime {
    NSTimeInterval fromNow = atTime - self.deviceCurrentTime_preIOS4;
    return [NSTimer scheduledTimerWithTimeInterval:fromNow target:self selector:@selector(play) userInfo:nil repeats:NO];
}

最新更新