Reputation: 21
I tried to find BPM using AVFoundation
framework but getting 0
as a result and not able to get BPM.
Here is my code,
MPMediaItem * mediaItem = [[collection items] objectAtIndex: 0];
NSString * albumIDKey = [MPMediaItem persistentIDPropertyForGroupingType: MPMediaGroupingAlbum];
NSLog(@"mpmediaitem:%@", albumIDKey);
int BPM = [[mediaItem valueForProperty: MPMediaItemPropertyBeatsPerMinute] intValue];
NSString * bpm = [mediaItem valueForProperty: MPMediaItemPropertyBeatsPerMinute];
NSLog(@"bpm:%@", bpm);
NSURL * url = [mediaItem valueForProperty: MPMediaItemPropertyAssetURL];
Am I missing anything here?
Upvotes: 0
Views: 1335
Reputation: 9169
The BPM is extracted from the metadata accompanying the audio file. Which often is not present. It is not calculated from the audio.
Also be aware that any BPM metadata that does exist is flawed by the assumption that a track has a constant tempo. Not always a safe assumption.
Quality audio-metadata can be obtained from The Echonest
Upvotes: 2