I'm working on an up-next/queue view for an app and but when the user reorders the queue, the player either does nothing and carries on playing the normal order or with added code, it has a very small pause before it updates the queue. The question is similar to Brief stop/start of Now Playing item when updating a media collection queue MPMediaItemCollection but there is no working answer. Here is my code:
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()
}
This method pauses the track before using the updated queue. Any way to do it without it pausing?
Thanks!