nowPlayingItem + 1并不总是播放下一首歌

时间:2016-04-05 05:24:38

标签: swift collections mpmusicplayercontroller

每次按下某个按钮时,我都会设置以下代码。现在前几首歌曲播放时间为1,然后从7跳到10,然后每次滚动3,然后从13跳到17,每次开始滚动4。任何想法如何或为什么nowPlayingInt可以在musicPlayer逐步浏览歌曲时变化超过1?

    let nowPlayingInt = delegate.queryAsCollection!.items.indexOf(delegate.musicPlayer.nowPlayingItem!)
    print("nowPlayingInt number is \(nowPlayingInt)")
    delegate.musicPlayer.nowPlayingItem = delegate.queryAsCollection!.items[nowPlayingInt! + 1]

我知道我可以使用.skipToNextItem,但这并不是我想要做的事情,如果我想跳过1首以上的歌曲,我就不会帮助我。< / p>

AppDelegate包含:

let musicPlayer = MPMusicPlayerController.systemMusicPlayer()    
var queryAsCollection : MPMediaItemCollection?
var collectionForNextUps = MPMediaQuery()

1 个答案:

答案 0 :(得分:0)

我让indexofNowPlayingItem按照需要工作。仍然不确定为什么与indexOf一致的行没有做到这一点,但我认为我发布的答案至少要完整一点。

    let nowPlayingInt = delegate.musicPlayer.indexOfNowPlayingItem
    print("nowPlayingInt number is \(nowPlayingInt)  1  ")
    delegate.musicPlayer.nowPlayingItem = delegate.queryAsCollection!.items[nowPlayingInt + 1]