0

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!

Community
  • 1
  • 1
air6199
  • 423
  • 3
  • 12

1 Answers1

0

Fix for part 1 only:

Managed to fix it! I just moved the code that sets the new queue under a "NowPlayingItemChanged" notification. Every time the silent notification is set off, the queue from the app delegate is set to play. This means no pauses as the previous song had just finished.

air6199
  • 423
  • 3
  • 12