Search code examples
iphoneobjective-cxcodeios4

How to determine the bpm (beats per minute) of any song, using iPhone SDK?


I am working on an iPhone app that can determine the bpm (beats per minute) of every song in the iTunes library, and then adjust the songs to 140 bpm (or 70) for the perfect workout tempo.

I have worked on the AVAsset library for capturing the songs from the itunes library, and this part is working fine. Now I want to capture and then modify the bpm (beats per minute) of that song.

I would really appreciate, if someone can show me the way that how this can be achieved, and if there is any sample available.


Solution

  • Load the song in AVPLayer. It has setRate functionality to change the tempo of the song.

    To read BPM of a song you need to use MPMediaItem. ex.

     MPMediaItem *mediaItem = ...;
     int BPM = [[mediaItem valueForProperty:MPMediaItemPropertyBeatsPerMinute]intValue];
    

    let me know if you need more explanation