Reputation: 3234
How to find the total duration of the audiofile playing so that i can program to display the contents of the audiofile in viewcontrollers according to the time.
if ([audioPlayer currentTime] ==11){
[self performSelector:@selector(viewController) withObject:nil];
} else {
if ([audioPlayer currentTime] ==23){
[self performSelector:@selector(secondViewController) withObject:nil];
}
Upvotes: 1
Views: 125
Reputation: 12405
Use the AudioFileServices functions...
NSURL *afUrl = [NSURL fileURLWithPath:soundPath];
AudioFileID fileID;
OSStatus result = AudioFileOpenURL((CFURLRef)afUrl, kAudioFileReadPermission, 0, &fileID);
UInt64 outDataSize = 0;
UInt32 thePropSize = sizeof(UInt64);
result = AudioFileGetProperty(fileID, kAudioFilePropertyEstimatedDuration, &thePropSize, &outDataSize);
AudioFileClose(fileID);
for more info refer these links.. http://developer.apple.com/library/ios/#codinghowtos/AudioAndVideo/_index.html https://developer.apple.com/library/mac/#documentation/musicaudio/reference/AudioFileConvertRef/Reference/reference.html
EDIT: This is to get the length of file even if it is not associated with the AVPlayer.. so you can populate a list ... hoping this helps somebody.. :D
Upvotes: 1
Reputation: 44698
If you're using AVAudioPlayer
, you can use it's duration
property to retrieve the length of the loaded audio file in seconds.
Upvotes: 1