Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

skipPrevious and skipNext buttons inactive even with items in queue Google Cast iOS Sender SDK v4.3.5 and above

I have an iOS sender application for video streaming that supports queueing and using the skipPrevious and skipNext buttons to skip forward and backward between videos in the queue. The app works with the google cast sdk v4.3.3 and v4.3.4 but I need to update the sdk to support iOS 13 changes. When I updated the sdk to v4.4.4 the skipPrevious and skipNext button types on the ExpandedMediaControlsViewController always appear greyed out even when I can see both on the receiver and by printing in the sender app that there are items in the queue. The buttons appear greyed out in all versions of the sdk v4.3.5 and later.

I have looked at the Google Chromecast developer documentation and the skipPrevious and skipNext button types are not deprecated and say that they should update automatically if there is something in the queue. I tried modifying google's iOS sender app tutorial code to change the 30 second ffw and rwd buttons to the skip buttons and had the same results after adding items to the queue and playing.

There is another unanswered question about a similar issue that was created in March here: skipNext skipPrevious Google Cast greyed out

I am using an update function inside of my castViewController class to change the expandedMediaControls to the skipPrevious and skipNext types. I call this method when my castViewController gets initialized

private func updatePlayerMediaControls() {
  GCKCastContext.sharedInstance().defaultExpandedMediaControlsViewController.setButtonType(.skipPrevious, at: 1)
  GCKCastContext.sharedInstance().defaultExpandedMediaControlsViewController.setButtonType(.skipNext, at: 2)
} 

I use a function that follows this logic to cast a video or add a video to the queue. Immediately after adding a video to the cast I will add the next video to the queue by setting the appending bool to true.

func loadSelectedItem(_ media: VideoMediaInformation, byAppending appending: Bool) {
  if let remoteMediaClient = sessionManager.currentCastSession?.remoteMediaClient {
    let mediaQueueItemBuilder = GCKMediaQueueItemBuilder()
    mediaQueueItemBuilder.mediaInformation = media.mediaInfo
    mediaQueueItemBuilder.autoplay = true
    mediaQueueItemBuilder.preloadTime = 1.0
    let queueOptions = GCKMediaQueueLoadOptions()
    queueOptions.playPosition = media.currentTime ?? 0.0
    if appending {
      let request = remoteMediaClient.queueInsert(mediaQueueItemBuilder.build(), beforeItemWithID: kGCKMediaQueueInvalidItemID)
      request.delegate = self
    } else {
      let request = remoteMediaClient.queueLoad([mediaQueueItemBuilder.build()], with: queueOptions))
      request.delegate = self
  GCKCastContext.sharedInstance().presentDefaultExpandedMediaControls()
    }
  }
}

I would expect that if there are items in the queue that the user would be able to use the skipNext and skipPrevious to skip forward or backward in the queue as episodes are available. The actual results are that the buttons are always disabled.

like image 522
myost Avatar asked Aug 23 '19 21:08

myost


1 Answers

I worked extensively with this issue. I was experiencing the exact same thing, as well as the issue referenced in the question. I attempted a full update of the library to 4.6.1. Since this package is a static library I was unable to inspect the cause. BUT Good News! I found a suitable work around. This solution does not take into account whether or not there is something available in the queue to move forward or backwards but it met my needs. In addition with the setup above I was able to use custom buttons that trigger the skip backward or forward.

@IBAction func playPressed(_ sender: UIButton) {
    // Create and add custom previous button
    let prevButton = UIButton()
    prevButton.setImage(Icon.mediaPlayerPrevious, for: .normal)
    prevButton.addTarget(self, action: #selector(castButtonPrevAction), for: .touchUpInside)
    GCKCastContext.sharedInstance()
        .defaultExpandedMediaControlsViewController
        .setButtonType(.custom, at: 0)
    GCKCastContext.sharedInstance()
        .defaultExpandedMediaControlsViewController
        .setCustomButton(prevButton, at: 0)
            
    // Create and add custom next button
    let nextButton = UIButton()
    nextButton.setImage(Icon.mediaPlayerNext, for: .normal)
    nextButton.addTarget(self, action: #selector(castButtonNextAction), for: .touchUpInside)
    GCKCastContext.sharedInstance()
        .defaultExpandedMediaControlsViewController
        .setButtonType(.custom, at: 3)
    GCKCastContext.sharedInstance()
        .defaultExpandedMediaControlsViewController
        .setCustomButton(nextButton, at: 3)

        
    // Presents the screen            
    GCKCastContext.sharedInstance().presentDefaultExpandedMediaControls()
}

// Casting custom button actions
@objc func castButtonNextAction(sender: UIButton!) {
    GMCastChannel.shared.remoteMediaClient?.queueNextItem()
}
@objc func castButtonPrevAction(sender: UIButton!) {
    GMCastChannel.shared.remoteMediaClient?.queuePreviousItem()
}
like image 85
Kory C Avatar answered Nov 03 '22 03:11

Kory C