Post

Replies

Boosts

Views

Activity

How to get "file" information from MPMediaItem
The Music macOS app shows various info about a song in the Get Info window. Most of this metadata is available in the iOS SDK via MPMediaItem. I'm wanting to access the information displayed in the File tab but I'm not seeing several pieces of data in the API. Is this possible? □ Kind - Apple Music AAC audio file - ? ☑︎ Duration - 3:00 - playbackDuration □ Size - 10 MB - ? □ Bit rate - 256 kbps - ? □ Sample rate - 44.100 kHz - ? □ Date modified - 1/1/2001 - ? ☑︎ Date added - 1/1/2001 - dateAdded □ Cloud status - Apple Music - ? ☑︎ Location - Cloud - isCloudItem
2
0
1.4k
Jun ’21
Possible to query for song by Apple Music trackId?
Given an Apple Music trackId is it possible to query the user’s media library to see if they’ve added it to their library? Something like: let predicate = MPMediaPropertyPredicate(value: "1440818675", forProperty: MPMediaItemPropertyPersistentID) let query = MPMediaQuery(filterPredicates: Set([predicate])) let songs = query.items let isInLibrary = !songs.isEmpty
3
0
1.9k
Jun ’21
Is it possible to get a song's bit rate from MPMediaItem?
I'd like to get a song's bit rate, for example 256 kbps, from a MPMediaItem retrieved via MPMediaPickerController. Is this possible? I tried to get it via: AVAsset(url: mediaItem.assetURL).tracks.first?.estimatedDataRate but this is 0 for most songs I've tried, and it's 127999 for a song that's really 64 kbps. I can get the sample rate of 44100 via: let trackDescription = AVAsset(url: url).tracks.first?.formatDescriptions.first let basicDescription = CMAudioFormatDescriptionGetStreamBasicDescription(trackDescription as! CMAudioFormatDescription)?.pointee let sampleRate = basicDescription.mSampleRate Supposedly one can calculate the bit rate given the sample rate, bit depth, and channels count, but I'm seeing mBitsPerChannel is always 0 in my testing.
0
0
824
Jun ’21