Better way to do skip to previous with AVQueuePlayer?

后端 未结 6 1131
难免孤独
难免孤独 2020-12-28 18:29

I am using an AVQueuePlayer in my app. I have a two swipe gestures to skip to next and skip to previous avplayeritems. Right now to do skip to next I am just ca

6条回答
  •  清酒与你
    2020-12-28 19:00

    You can replace your current item with the previous and add the item, that was replaced:

    let previousItem = AVPlayerItem(url: url )
    let currentItem = AVPlayerItem(url: currentUrl)
    
     player.replaceCurrentItem(with: previousItem)
        if player.canInsert(currentItem, after: previousItem) {
             player.insert(currentItem, after: previousItem)
        }
    

    // OR like this

     let previousItem = AVPlayerItem(url: url )
     if let currentItem = player.currentItem {
       player.replaceCurrentItem(with: previousItem)
         if player.canInsert(currentItem, after: previousItem) {
             player.insert(currentItem, after: previousItem)
         }
      }
    

提交回复
热议问题