How To Distinguish One Music File From The Other - ios

I am currently building a music player app. One of the functions of my app is "My Favorites". This is nothing different from other music player apps, for it allows user to mark down their favorite songs, and when they want to play only their favorite songs, they can play them directly from the "My Favorites" list.
My problem now is that in order for me to remember and be able to play that song next time, I think I have to remember the UNIQUE ID of that song. I am not sure if there is really a UNIQUE ID for every music file stored in the phone. I just thought of that because if there is, it would be a key for me to access that music file.
The solution I tried is appending the name of the music and the artist and use it as the key. Then, I will get the music list and run a loop through it, once I find the corresponding music file by comparing it with the key I will store it in an NSMutableDictionary. Then I will be able to play it later.
The problem of my solution is that what id two music files have exactly the same artist name and same title. That I won't be able to distinguish which is which.
I hope I made my self clear. To summarize:
Problem: Is there a way to get the UNIQUE ID of a music file. If there isn't are there any other ways to determine one music file from the other?

As what #Larme suggested. I could use MPMediaItemPropertyPersistentID for the unique ID of my music files, and that is what I've applied, and it is the right answer for me.
Thank you #Larme!

Related

Twilio video tracks differentiation

In my application i have a user that is simultaneously using two video tracks (screen sharing and a webcam). Firs when the user connects The webcam starts and then the screen sharing track gets added.
In the muddle of this session i need an ability to enable the user camera switching. I used this guide here to implement this feature: https://www.twilio.com/blog/2018/06/switching-cameras-twilio-video-chat.html
However when i do something like this:
const tracks = Array.from(localParticipant.videoTracks.values());
localParticipant.unpublishTracks(tracks);
localParticipant.publishTrack(localVideoTrack);
I unpublish both video tracks(screen sharing and camera) and only adding a camera track. Is there a way to add a property to the track(other than "kind") that will allow me to make this distinction?
Because right now the only way i can do it is tracking if the user has screen sharing enabled and re-connect both tracks in this case.
Twilio developer evangelist here.
All Tracks within Twilio Video have a name property which is the track ID by default. However, you can set the name of the track when you create or publish it.
For example:
localParticipant.publishTrack(localVideoTrack, { name: "camera" }
You can then read the name from the LocalTrack or RemoteTrack object later.
Let me know if that helps.

iOS MPMediaItem: Options as set in iTunes

When loading MPMediaItems via the MPMediaLibrary (MediaPlayer Framework), I'm looking for a way to access the start, stop, and volume properties as they can be set in iTunes via right click on a song => Get Info => Options.
These properties are not properties of MPMediaItem, and I'm not (yet?) able to access them via AVAsset either.
When playing the MPMediaItem using the MPMusicPlayerController applicationMusicPlayer, it does play the track from the set start point. However I need to use AVAudioPlayer and would therefore like to find a way to fetch these settings programmatically.
Any help or hints would be much appreciated!

Unique Id for MPMediaItem rather then persistentID

By using the persistentID for uniquely identify the song but we have the provision in music app to add the same song multiple times to the playlist this tends to have same song many times in the playlist along with same persistentID so I can't able to the find out the which song is currently selecting because all the songs has the same persistentID. Is there any alternative to identify the MPMediaItem rather then persistentID.
NOTE: I can't decide through selected cell on the UITableView too because it has some other dependencies.
How about using the playbackStoreID from MPMediaItem?
See https://developer.apple.com/documentation/mediaplayer/mpmediaitem/2813404-playbackstoreid

Get Apple Music playlist share URL programmatically by Swift

When sharing playlist in Apple Music app via Email, you can get a URL like this
https://itunes.apple.com/jp/playlist/if-you-like...may-j./idpl.4299b4c5a42048bd850eca538e68ace2?l=en
You will also have an URL when sharing local created playlist.
I would like to know if it is possible to get the URL programmatically on iOS using Swift.
[Effort studied but failed to solve]
Related discussion using link maker does not solve the problem
Apple Music URL Scheme
Query the playlist using: MPMediaQuery.playlists() and enumerated the returned playlist but cannot find any property showing the URL
I'm pretty sure this is not possible. I believe the playlist does not have the idpl value until the user manually presses the share button in iTunes. And, there's nothing in the API to create one.
I set up a proxy and had a look at the requests iTunes makes.
I created a playlist in iTunes and added songs to the playlist. Every song I added made several requests to various endpoints under:
https://ld-6.itunes.apple.com/WebObjects/MZDaap.woa/daap/update No idpl value in any of the responses.
Then I manually hit the share button. A request is made to
https://client-api.itunes.apple.com/WebObjects/MZStorePlatform.woa/wa/lookup with the idpl in the URL.
Now when you add more songs to the playlist, the responses contain the idpl.
From that it seems that the idpl is created on the device when the user touches share.
Probably best to file a radar for Apple to add a share URL property to MPMediaPlaylist.
EDIT: I filed a radar

How to through the gracenote playlist ident (eg: 0_12) get the name of the song

I have a confused, I want to through the generation of playlist in the ident (eg: 0_11) to get the song name, what shoud I do and those functions can be used. thank you!
Collection Summaries in Gracenote Playlist do not store any metadata. The Collection Summary only stores the identifier for a piece of media that your application gives it. Playlists that are generated will only return these identifiers.
It is up to your application to use these identifiers to refer back to the media to do what you wish (in your case, to get the track name). Most media applications already have a media database of their own, so the identifier is normally a reference into the application's media store.
TL;DR;
You need to create a database that maps the Playlist identifiers to the song name.

Resources