AVAudioPlayer's playAtTime Property doesn't working in IOS 3.0 / App Crash
Am developed a universal application which 开发者_StackOverflow社区reads a audio file from local and will play using AvAudioPlayer. Here i using PlayAtTime property of AvAudioPlayer to forward and backward the audio.
Here my problem is this playAtTime property is working fine with ios 4.0 and later and not working in IOS-3.0.
I refered framwork which says - (BOOL)playAtTime:(NSTimeInterval)time NS_AVAILABLE(10_7, 4_0);
in the sense i cant use it in ios 3.0 right..?? then whats the fix for ios 3.0
is there any solution to overcome this. And any suggestion.??
A quick look at the documents will clearly let u know that it is available only from iOS 4.0 onwards
Availability
Available in iOS 4.0 and later.
Try
currentTime
The playback point, in seconds, within the timeline of the sound associated with the audio player.
@property NSTimeInterval currentTime
Discussion
If the sound is playing, currentTime is the offset of the current playback position, measured in seconds from the start of the sound. If the sound is not playing, currentTime is the offset of where playing starts upon calling the play method, measured in seconds from the start of the sound.
By setting this property you can seek to a specific point in a sound file or implement audio fast-forward and rewind functions.
playAtTime is available from iOS 4.0, see the doc for more info ;)
http://developer.apple.com/library/ios/#DOCUMENTATION/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html
if you are not fussed about super accurate syncing, you can always try something like this instead (will work in IOS4+ as well, just not as accurately). note - to cancel it you need to save the return value and send it an "[mySavedTimer invalidate]" message.
@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];
}
精彩评论