I'm trying to convert an MPMediaItem to NSData object so I can play it with AVAudioPlayer. The following answer was posted a while back on a similar question, with steps on how to to that:
Of course you can access the data of a MPMediaItem. It's not crystal clear at once but it works. Here's how:
Get the media item's URL from it's MPMediaItemPropertyAssetURL property Initialize an AVURLAsset with this URL Initialize an AVAssetReader with this asset Fetch the AVAssetTrack you want to read from the AVURLAsset Create an AVAssetReaderTrackOutput with this track Add this output to the AVAssetReader created before and -startReading Fetch all data with AVAssetReaderTrackOutput's -copyNextSampleBuffer PROFIT!
After fetching the data with 'copyNextSampleBuffer', I now have an CMSampleBufferRef object. How do I continue from here?
Thanks, Gili
Try this:
Try to use following code