MPMusicPlayerController setQueueWithStoreIDs 播放索引?
it1352
帮助1人
问题说明
我在使用音乐播放器时遇到问题,当我使用 Store 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()
正确答案
#1
我发现解决方案可能会帮助别人,我应该使用 MPMusicPlayerStoreQueueDescriptor
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()
}
}
}
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcgabbf
系列文章
更多
-
在C#代码查找所有递归调用
-
Git Cherry-pick 和合并工作流
-
React Native TextInput blur消耗TouchableHighlight按事件
-
替换"#"," $","%","&放大器;"和" _"和" \\#"," \\ $"," \\%QUOT;," \\&安培;"和" \\ _"
-
pandas :不同的功能应用于不同的列
-
DOMDocument :: validate()问题
同类精品
更多
-
在C#代码查找所有递归调用
-
Git Cherry-pick 和合并工作流
-
React Native TextInput blur消耗TouchableHighlight按事件
-
替换"#"," $","%","&放大器;"和" _"和" \\#"," \\ $"," \\%QUOT;," \\&安培;"和" \\ _"
-
pandas :不同的功能应用于不同的列
-
DOMDocument :: validate()问题
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20