【问题标题】:Remove pause after setting new queue?设置新队列后删除暂停?
【发布时间】:2015-05-01 20:08:26
【问题描述】:

我正在处理应用程序的上一个/队列视图,但是当用户重新排序队列时,播放器要么什么都不做,继续播放正常顺序或添加代码,它有一个非常小的停顿在它更新队列之前。该问题类似于Brief stop/start of Now Playing item when updating a media collection queue MPMediaItemCollection,但没有有效的答案。这是我的代码:

override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
    var itemToMove = self.queueCopy[fromIndexPath.row + self.currentIndex] as MPMediaItem
    self.queueCopy.removeObjectAtIndex(fromIndexPath.row + self.currentIndex)
    self.queueCopy.insertObject(itemToMove, atIndex: toIndexPath.row + self.currentIndex)

    let newQueue = MPMediaItemCollection(items: self.queueCopy)

    let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
    appDelegate.currentQueue = newQueue

    MPMusicPlayerController.iPodMusicPlayer().setQueueWithItemCollection(newQueue)
    var currentTime = MPMusicPlayerController.iPodMusicPlayer().currentPlaybackTime
    var currentIndex = MPMusicPlayerController.iPodMusicPlayer().indexOfNowPlayingItem
    MPMusicPlayerController.iPodMusicPlayer().nowPlayingItem = newQueue.items[currentIndex] as MPMediaItem
    MPMusicPlayerController.iPodMusicPlayer().currentPlaybackTime = currentTime
    MPMusicPlayerController.iPodMusicPlayer().play()

}

此方法在使用更新的队列之前暂停轨道。有什么方法可以在不暂停的情况下做到这一点?

谢谢!

【问题讨论】:

  • 您可以检查曲目是否播放,然后更新播放。
  • @cmashinho 我将如何更新它?无论玩家是否在玩,我都设置了上面的队列,所以它应该可以正常工作吗?

标签: ios swift


【解决方案1】:

仅修复第 1 部分:

设法修复它!我只是在“NowPlayingItemChanged”通知下移动了设置新队列的代码。每次设置静音通知时,应用程序委托的队列都会设置为播放。这意味着没有停顿,因为上一首歌刚刚结束。

【讨论】:

    猜你喜欢
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-07
    • 1970-01-01
    • 2023-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多