与How to add/use GCKMediaQueue in Swift?有关,我在AppDelegate上添加了跳过按钮,它们确实出现在扩展的控制器屏幕上。但是它们变灰了。如果我让视频结束,那么它将播放队列中的下一个。但是,为什么按钮变灰了呢?这通常意味着它们不可用。但是我队列中有50个视频,所以我想念什么?
func addvideos2queue() {
for indexloop in 1 ... 50
{
debugPrint("**** Attempting #" + String(indexloop) + " to add another to the que")
let PTV = playthisvideo() //received random video file name
let metadata = GCKMediaMetadata()
metadata.setString("Los Simpsons", forKey: kGCKMetadataKeyTitle)
metadata.addImage(GCKImage(url: URL(string: self.location + "poster_los_simpson.jpg")!,
width: 480,
height: 360))
metadata.setString (PTV,
forKey: kGCKMetadataKeySubtitle)
let url = URL.init(string: (self.location + PTV))
guard let mediaURL = url else {
print("**** invalid mediaURL")
return }
if url == nil {debugPrint("***** URL was empty")}
let mediaInfoBuilder = GCKMediaInformationBuilder.init(contentURL: mediaURL)
mediaInfoBuilder.streamType = GCKMediaStreamType.none;
mediaInfoBuilder.contentType = "video/mp4"
mediaInfoBuilder.contentID = String(indexloop)
mediaInfoBuilder.metadata = metadata;
let builder = GCKMediaQueueItemBuilder()
let mediaInformation = mediaInfoBuilder.build()
builder.mediaInformation = mediaInformation
builder.autoplay = true
builder.preloadTime = 15
let item = builder.build
if let remoteMediaClient = GCKCastContext.sharedInstance().sessionManager.currentCastSession?.remoteMediaClient {
if remoteMediaClient.mediaStatus != nil, true {
let request = remoteMediaClient.queueInsert([item()], beforeItemWithID: kGCKMediaQueueInvalidItemID, customData: kGCKMediaCommandSkipForward)
request.delegate = self
debugPrint(" ***** ITS BEEN ADDED ****", request)
setQueueButtonVisible(true)
} else {
let options = GCKMediaQueueLoadOptions()
options.repeatMode = .all
options.customData = kGCKMediaCommandSkipForward
debugPrint (" ************* First one ", (item()))
let request = remoteMediaClient.queueLoad([item()], with: options )
request.delegate = self
}
}
}//new end of loop
GCKCastContext.sharedInstance().presentDefaultExpandedMediaControls() // Brings to expaned controller up
}//end of castanthoner