Search code examples
iosaudiompmediaitemmpmediaplayercontroller

MPMusicPlayerController Track Length


Using an MPMusicPlayerController is there a way to query the tracks length?

Using .currentPlaybackTime I can figure out how far I am into the track but I have no way of knowing how long the track is.

My [MPMediaItem valueForProperty:MPMediaItemPropertyAssetURL] returns null for some tracks so using the AVAsset won't work for me.


Solution

  • Easy just use

       NSNumber *duration=[item valueForProperty:MPMediaItemPropertyPlaybackDuration];