I would like to skip to another song using the index number of an item (that you can find with playlist.indexOfNowPlayingItem). Is there an easy way to do that with a function like mediaplayer.skipToNextItem but setting the index number ( for example mediaplayer.skipToItem(4) if i want to skip to the fourth item of my playlist) ?
The solution is, creating a collection as MPMediaItemCollection
, to set the song to play with : player.nowPlayingItem = collection.items[1]
for example :
var query = MPMediaQuery.songsQuery()
var collection = MPMediaItemCollection(items: query.items!) //it needs the "!"
let player = MPMusicPlayerController.applicationMusicPlayer()
player.setQueueWithItemCollection(collection)
player.nowPlayingItem = collection.items[1]
Note : Ifound the answer here : Play Song at specific index of MPMediaItemCollection in Swift