MPMusicPlayerController setQueueWithStoreIDs播放索引吗? [英] MPMusicPlayerController setQueueWithStoreIDs playing index?
本文介绍了MPMusicPlayerController setQueueWithStoreIDs播放索引吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在音乐播放器上遇到问题,当我使用商店ID设置队列并调用方法play()
其播放优先轨道时,如何使它播放队列的X索引?
i am having issue with music player , when i set queue with Store id's and call method play()
its play first track , how i can make it play X index of queue ?
var ids:[String] = []
for song in self.queue
{
ids.append(String(song.epf_song_id))
}
print("ids \(ids.count)")
applicationMusicPlayer.setQueueWithStoreIDs(ids)
applicationMusicPlayer.play()
推荐答案
i found the solution maybe will help someone else , i should use MPMusicPlayerStoreQueueDescriptor
func playByStoreID( storeIds:[String] )
{
DispatchQueue.main.async {
//Prepare before play ios 10.1 and above
if #available(iOS 10.1, *)
{
var ids:[String] = []
for i in self.queue
{
ids.append(String(i.epf_song_id))
}
let descriptor:MPMusicPlayerStoreQueueDescriptor = MPMusicPlayerStoreQueueDescriptor(storeIDs: ids)
descriptor.startItemID = storeIds[0]
self.applicationMusicPlayer.setQueue(with: descriptor)
self.applicationMusicPlayer.prepareToPlay { (error) in
//Wait 5 seconds
if (error != nil)
{
let errorCode:Int = (error! as NSError).code
print("[MUSIC PLAYER] Error \(String(describing: error))")
if errorCode == 4 && self.currectPlaying.failed == 0
{
print("[MUSIC PLAYER] Error Load track will play again after 5 seconds")
self.applicationMusicPlayer.stop()
self.currectPlaying.failed += 1
DispatchQueue.main.asyncAfter(deadline: .now() + 5 , execute: {
self.play_from_apple( false )
})
}else
{
//Inform player to play with another streamer
self.fullFailure()
print("[MUSIC PLAYER] Error preparing : \(String(describing: error))")
}
return
}else
{
self.applicationMusicPlayer.play()
self.playedBy = .apple
}
}
}else
//Play directly ios below version 10.1
{
self.applicationMusicPlayer.setQueue(with: storeIds)
self.applicationMusicPlayer.play()
}
}
}
这篇关于MPMusicPlayerController setQueueWithStoreIDs播放索引吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文