Access to the BPM field in the song (MPMediaItemPropertyBeatsPerMinute does not work)

I am creating an application that has a media player (I am using iOS SDK 4.2). Although this song plays, I can access almost every property, but I cannot access MPMediaItemPropertyBeatsPerMinute.

It returns null every time.

Apple doc claims:

The number of musical beats per minute for the media item, the corresponding "BPM" field on the "Information" tab in the "Get Information" dialog box in iTunes. Value is an NSNumber object representing the NSUInteger data type.

Available in iOS 4.0 and later.

Declared in MPMediaItem.h.

Please note that the songs I use have BPM data in the BPM field. I know that it is not installed by default.

The code I tried:

MPMusicPlayerController *musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
// ...
MPMediaItem *currentItem = [musicPlayer nowPlayingItem];
if (currentItem != NULL) {
  NSLog([NSString stringWithFormat:@"%@", [currentItem valueForProperty:MPMediaItemPropertyBeatsPerMinute]]);
}

The code above splashes out "(null)" for each song.

Since I was able to access any other property of the current song this way, I believe that this could be a bug in the SDK.

So my question is a little twofold.

  • Am I doing it wrong or is it a known bug in the SDK?
  • How else can I find BPM data in a song?
+2
source share
1 answer

I tested this problem with iOS SDK 4.3 and I can confirm that it works. However, your code looks fine.

4.2 SDK, 4.3. , iTunes BPM .

@"beatsPerMinute" MPMediaItemPropertyBeatsPerMinute ( iOS 4.3), , .

+3

Source: https://habr.com/ru/post/1540344/


All Articles