Jason Silberman
Jason Silberman

Reputation: 2491

Get iTunes URL of MPMediaItem

Is there a way to get the iTunes URL of a MPMediaItem? So I can open that song in iTunes?

I would like to be able to have an "open this song in iTunes" option like Shazam does once you have found a song you like.

Thanks

Upvotes: 2

Views: 1011

Answers (3)

Tim Lin
Tim Lin

Reputation: 163

Since iOS 10.3, we are able to get a something call playbackStoreID from a MPMediaItem, however, it sometimes return "0" instead of a real media id on iTunes store.

@Marcus Stemple mentioned you can get an url from "MPMediaItemPropertyAssetURL", but it is not guarantee to be returned.

I think for now the better way might be using the information you have from a MPMediaItem such as Artist name and track name to make query to the iTunes Search API and then retrieve the most closet result it found.

Upvotes: 0

Marcus Stemple
Marcus Stemple

Reputation: 120

MPMediaItem has a property called MPMediaItemPropertyAssetURL that should hold the URL you're looking for, at least when you don't have the song available offline, which it sounds like you don't.

Upvotes: 1

Oren
Oren

Reputation: 5103

I'm looking to do the same thing. The only solution I can think of is using iTunes Search API based off the title, album, artist, etc on MPMediaItem. Far from ideal because results may not match but it works for my needs.

Upvotes: 0

Related Questions